def execute_using_pool(self, pool, **kwargs): """Used by the worker to send this task to the pool. Arguments: pool (~celery.concurrency.base.TaskPool): The execution pool used to execute this request. Raises: celery.exceptions.TaskRevokedError: if the task was revoked. """ task_id = self.id task = self.task if self.revoked(): raise TaskRevokedError(task_id) time_limit, soft_time_limit = self.time_limits result = pool.apply_async( trace_task_ret, args=(self.type, task_id, self.request_dict, self.body, self.content_type, self.content_encoding), accept_callback=self.on_accepted, timeout_callback=self.on_timeout, callback=self.on_success, error_callback=self.on_failure, soft_timeout=soft_time_limit or task.soft_time_limit, timeout=time_limit or task.time_limit, correlation_id=task_id, ) # cannot create weakref to None self._apply_result = maybe(ref, result) return result
def execute_using_pool(self, pool, **kwargs): task_id = self.task_id if (self.expires or task_id in revoked_tasks) and self.revoked(): raise TaskRevokedError(task_id) time_limit, soft_time_limit = self.time_limits result = apply_async( trace, args=( self.type, task_id, self.request_dict, self.body, self.content_type, self.content_encoding, ), accept_callback=self.on_accepted, timeout_callback=self.on_timeout, callback=self.on_success, error_callback=self.on_failure, soft_timeout=soft_time_limit or default_soft_time_limit, timeout=time_limit or default_time_limit, correlation_id=task_id, ) # cannot create weakref to None # pylint: disable=attribute-defined-outside-init self._apply_result = maybe(ref, result) return result
def execute_using_pool(self, pool, **kwargs): """Like :meth:`execute`, but using a worker pool. :param pool: A :class:`celery.concurrency.base.TaskPool` instance. :raises celery.exceptions.TaskRevokedError: if the task was revoked and ignored. """ task = self.task if self.revoked(): raise TaskRevokedError(self.id) hostname = self.hostname kwargs = self.kwargs if task.accept_magic_kwargs: kwargs = self.extend_with_default_kwargs() request = self.request_dict request.update({ 'hostname': hostname, 'is_eager': False, 'delivery_info': self.delivery_info, 'group': self.request_dict.get('taskset') }) result = pool.apply_async(trace_task_ret, args=(self.name, self.id, self.args, kwargs, request), accept_callback=self.on_accepted, timeout_callback=self.on_timeout, callback=self.on_success, error_callback=self.on_failure, soft_timeout=task.soft_time_limit, timeout=task.time_limit) return result
def execute_using_pool(self, pool, **kwargs): """Used by the worker to send this task to the pool. :param pool: A :class:`celery.concurrency.base.TaskPool` instance. :raises celery.exceptions.TaskRevokedError: if the task was revoked and ignored. """ task_id = self.id task = self.task if self.revoked(): raise TaskRevokedError(task_id) time_limit, soft_time_limit = self.time_limits result = pool.apply_async( trace_task_ret, args=(self.type, task_id, self.request_dict, self.body, self.content_type, self.content_encoding), accept_callback=self.on_accepted, timeout_callback=self.on_timeout, callback=self.on_success, error_callback=self.on_failure, soft_timeout=soft_time_limit or task.soft_time_limit, timeout=time_limit or task.time_limit, correlation_id=task_id, ) # cannot create weakref to None self._apply_result = ref(result) if result is not None else result return result
def mark_as_revoked(self, task_id, reason='', request=None, store_result=True, state=states.REVOKED): exc = TaskRevokedError(reason) if store_result: self.store_result(task_id, exc, state, traceback=None, request=request) if request and request.chord: self.on_chord_part_return(request, state, exc)
def play_workflow(self, workflow, step_id=None): result = None if step_id is not None: step = workflow.get_step_by(id=step_id) if not workflow.is_ready(step=step): raise TaskRevokedError('Predecessors are not yet finished.') result = step.run() self.update_state(state=SUCCESS) next_steps = list(workflow.successors(step)) else: next_steps = workflow.get_roots() for step in next_steps: step.id = str(uuid4()) play_workflow.apply_async(args=( workflow, step.id, ), task_id=step.id) return result
def execute_using_pool(self, pool, **kwargs): """Used by the worker to send this task to the pool. :param pool: A :class:`celery.concurrency.base.TaskPool` instance. :raises celery.exceptions.TaskRevokedError: if the task was revoked and ignored. """ uuid = self.id task = self.task if self.revoked(): raise TaskRevokedError(uuid) hostname = self.hostname kwargs = self.kwargs if task.accept_magic_kwargs: kwargs = self.extend_with_default_kwargs() request = self.request_dict request.update({ 'hostname': hostname, 'is_eager': False, 'delivery_info': self.delivery_info, 'group': self.request_dict.get('taskset') }) timeout, soft_timeout = request.get('timelimit', (None, None)) timeout = timeout or task.time_limit soft_timeout = soft_timeout or task.soft_time_limit result = pool.apply_async( trace_task_ret, args=(self.name, uuid, self.args, kwargs, request), accept_callback=self.on_accepted, timeout_callback=self.on_timeout, callback=self.on_success, error_callback=self.on_failure, soft_timeout=soft_timeout, timeout=timeout, correlation_id=uuid, ) # cannot create weakref to None self._apply_result = ref(result) if result is not None else result return result
def execute_using_pool(self, pool, **kwargs): task_id = self.id if (self.expires or task_id in revoked_tasks) and self.revoked(): raise TaskRevokedError(task_id) time_limit, soft_time_limit = self.time_limits result = apply_async( trace, args=(self.type, task_id, self.request_dict, self.body, self.content_type, self.content_encoding), accept_callback=self.on_accepted, timeout_callback=self.on_timeout, callback=self.on_success, error_callback=self.on_failure, soft_timeout=soft_time_limit or default_soft_time_limit, timeout=time_limit or default_time_limit, correlation_id=task_id, ) # cannot create weakref to None self._apply_result = ref(result) if result is not None else result return result
def mark_as_revoked(self, task_id, reason='', request=None): return self.store_result(task_id, TaskRevokedError(reason), status=states.REVOKED, traceback=None, request=request)
def mark_as_revoked(self, task_id): return self.store_result(task_id, TaskRevokedError(), status=states.REVOKED, traceback=None)