def consolidate(self, items, queryset): if app.conf.task_always_eager: return items for item in items: if isinstance(item["channel"], uuid.UUID): item["channel"] = item["channel"].hex # @see contentcuration.utils.celery.tasks:CeleryAsyncResult task_result = app.AsyncResult(item["task_id"]) if not task_result: return item progress = task_result.progress result = task_result.result metadata = {} if task_result.status in states.EXCEPTION_STATES: metadata.update(error={'traceback': task_result.traceback}) if isinstance(result, Exception): result = task_result.traceback progress = 100 elif not task_result.ready(): # overwrite result if not complete, since it would have progress data result = None item["status"] = task_result.status item["metadata"].update(progress=progress, result=result, **metadata) return items
def get_status(self, task): # If CELERY_TASK_ALWAYS_EAGER is set, attempts to retrieve state will assert, so do a sanity # check first. if not settings.CELERY_TASK_ALWAYS_EAGER: result = app.AsyncResult(task.task_id) if result and result.status: return result.status return task.status
def get_metadata(self, task): metadata = task.metadata result = app.AsyncResult(task.id) # If CELERY_TASK_ALWAYS_EAGER is set, attempts to retrieve state will assert, so do a sanity check first. if not settings.CELERY_TASK_ALWAYS_EAGER: if task.is_progress_tracking and 'progress' in result.state: metadata['progress'] = result.state['progress'] return metadata
def get_metadata(self, task): metadata = task.metadata # If CELERY_TASK_ALWAYS_EAGER is set, attempts to retrieve state will assert, so do a sanity check first. if not settings.CELERY_TASK_ALWAYS_EAGER: result = app.AsyncResult(task.task_id) # Just flagging this, but this appears to be the correct way to get task metadata, # even though the API is marked as private. meta = result._get_task_meta() if meta and 'result' in meta and meta['result'] and 'progress' in meta['result']: metadata['progress'] = meta['result']['progress'] return metadata
def consolidate(self, items, queryset): if not settings.CELERY_TASK_ALWAYS_EAGER: for item in items: result = app.AsyncResult(item["task_id"]) if result and result.status: item["status"] = result.status if "progress" not in item["metadata"]: # Just flagging this, but this appears to be the correct way to get task metadata, # even though the API is marked as private. meta = result._get_task_meta() if (meta and "result" in meta and meta["result"] and not isinstance(meta["result"], Exception) and "progress" in meta["result"]): item["metadata"]["progress"] = meta["result"][ "progress"] else: item["metadata"]["progress"] = None item["channel"] = (item.get("metadata", {}).get("affects", {}).get("channel")) return items