def newView(request): form = ParamForm(request.POST) # check whether it's valid: if request.method == 'POST' and 'btnform3' in request.POST: for i in range(len(ID)): task_id = ID[i] task = AsyncResult(task_id) progress = task.state PROGRESS[i] = progress task_id = FormGet.task_id task = AsyncResult(FormGet.task_id) progress = task.state # time.sleep(1) if task.ready(): getval = task.get() ID_ind=ID.index(task_id) PROGRESS[ID_ind]=task.state #getval = getval.encode('utf-8') #getval = base64.b64decode(getval) #response = HttpResponse(getval, content_type='image/png') #response['Content-Length'] = str(len(response.content)) return render_to_response('grapher/status_complete.html', {'form': form,'image': getval,'progress':PROGRESS,'ID' : ID}) return render(request, 'grapher/completion_status.html', {'form': form, 'progress': PROGRESS,'ID' : ID})
def dismiss_session_task( request, task_id ): """Dismiss a task from session_tasks. Removes 'startd' fields bc datetime objects not serializable to JSON. """ newtasks = {} tasks = request.session.get(settings.CELERY_TASKS_SESSION_KEY, {}) for tid in tasks.keys(): if tid != task_id: task = tasks[tid] if task.get('startd',None): task.pop('startd') newtasks[tid] = task request.session[settings.CELERY_TASKS_SESSION_KEY] = newtasks
def imagedisplay(request): task_id = FormGet.task_id task = AsyncResult(FormGet.task_id) for i in range(len(ID)): task_id = ID[i] task = AsyncResult(task_id) progress = task.state PROGRESS[i] = progress getval = task.get() IMAGE.append(getval) if task.ready(): # getval = task.get() # progress = task.state i = inspect() a=12 return render_to_response('grapher/png_template.html', { 'image': IMAGE,'apple':a})
def session_tasks( request ): """Gets task statuses from Celery API, appends to task dicts from session. This function is used to generate the list of pending/successful/failed tasks in the webapp page notification area. @param request: A Django request object @return tasks: a dict with task_id for key """ # basic tasks info from session: # task_id, action ('name' argument of @task), start time, args tasks = request.session.get(settings.CELERY_TASKS_SESSION_KEY, {}) # add entity URLs for task_id in tasks.keys(): task = tasks.get(task_id, None) if task and task['action'] in ['webui-file-new-master', 'webui-file-new-mezzanine', 'webui-file-new-access']: # Add entity_url to task for newly-created file repo,org,cid,eid = task['entity_id'].split('-') task['entity_url'] = reverse('webui-entity', args=[repo,org,cid,eid]) # Hit the celery-task_status view for status updates on each task. # get status, retval from celery # TODO Don't create a new ctask/task dict here!!! >:-O traceback = None for task_id in tasks.keys(): # Skip the HTTP and get directly from Celery API # djcelery.views.task_status result = AsyncResult(task_id) state, retval = result.state, result.result response_data = {'id': task_id, 'status': state, 'result': retval} if state in states.EXCEPTION_STATES: traceback = result.traceback response_data.update({'result': safe_repr(retval), 'exc': get_full_cls_name(retval.__class__), 'traceback': traceback}) # end djcelery.views.task_status task = response_data # construct collection/entity/file urls if possible if task: ctask = tasks[task['id']] ctask['status'] = task.get('status', None) ctask['result'] = task.get('result', None) # try to convert 'result' into a collection/entity/file URL if (ctask['status'] != 'FAILURE') and ctask['result']: r = ctask['result'] if type(r) == type({}): if r.get('id', None): oid = Identifier(r['id']) object_url = reverse('webui-%s' % oid.model, args=oid.parts.values()) ctask['%s_url' % oid.model] = object_url tasks[task['id']] = ctask # pretty status messages for task_id in tasks.keys(): task = tasks[task_id] action = task.get('action', None) if action: messages = TASK_STATUS_MESSAGES.get(action, None) status = task.get('status', None) template = None if messages and status: template = messages.get(status, None) if template: msg = template.format(**task) task['message'] = msg # indicate if task is dismiss or not for task_id in tasks.keys(): task = tasks[task_id] if task.get('status', None): task['dismissable'] = (task['status'] in TASK_STATUSES_DISMISSABLE) # include traceback in task if present if traceback: task['traceback'] = traceback # done return tasks