def format(self, record): # noqa: A003 task = current_task() if task and task.request: self._fmt = self._task record.__dict__.update( taskid=task.request.id, taskname=task.name, ) else: self._fmt = self._base return super(TaskFormatter, self).format(record)
def __call__(self, *args, **kwargs): task = current_task() try: context.update(task) except Exception as e: logger.debug('Failed to push task to log context: %r', e) try: return super(LoggingTask, self).__call__(*args, **kwargs) finally: context.clear()
def apply_async(self, connection=None, connect_timeout=None, publisher=None, taskset_id=None): """Apply group.""" app = self.app if app.conf.CELERY_ALWAYS_EAGER: return self.apply(taskset_id=taskset_id) with app.default_connection(connection, connect_timeout) as conn: setid = taskset_id or uuid() pub = publisher or self.Publisher(connection=conn) try: results = self._async_results(setid, pub) finally: if not publisher: # created by us. pub.close() result = app.TaskSetResult(setid, results) parent = current_task() if parent: parent.request.children.append(result) return result
def my_task(): context.update(taskField='RUNNED') logger = get_task_logger(current_task().name) logger.info("I log!") return context.as_dict()
def current_task_children(self): current = current_task() if current: return [r.serializable() for r in current.request.children]
def current_task_children(self, request=None): request = request or getattr(current_task(), 'request', None) if request: return [r.as_tuple() for r in getattr(request, 'children', [])]