def _send_call(self, my_task): """Sends Celery asynchronous call and stores async call information for retrieval laster""" arg, kwargs = None, None if self.args: args = _eval_args(self.args, my_task) if self.kwargs: kwargs = _eval_kwargs(self.kwargs, my_task) LOG.debug("%s (task id %s) calling %s" % (self.name, my_task.id, self.call), extra=dict(data=dict(args=args, kwargs=kwargs))) async_call = default_app.send_task(self.call, args=args, kwargs=kwargs) my_task._set_internal_attribute(task_id=async_call.task_id) my_task.async_call = async_call LOG.debug("'%s' called: %s" % (self.call, my_task.async_call.task_id))
def _send_call(self, my_task): """Sends Celery asynchronous call and stores async call information for retrieval laster""" arg, kwargs = None, None if self.args: args = eval_args(self.args, my_task) if self.kwargs: kwargs = eval_kwargs(self.kwargs, my_task) LOG.debug("%s (task id %s) calling %s" % (self.name, my_task.id, self.call), extra=dict(data=dict(args=args, kwargs=kwargs))) if default_app.conf.get("CELERY_ALWAYS_EAGER", False) is True: LOG.debug("Making synchronous call to '%s'" % self.call) if args is None: args = [] if kwargs is None: kwargs = {} # Load the celery task mod = __import__(self.call.split('.')[0]) components = self.call.split('.') for comp in components[1:-1]: mod = getattr(mod, comp) # Call it - This should return an EagerResult async_call = mod.__builtins__['getattr'](mod, components[-1]).delay( *args, **kwargs) LOG.debug("Call state is %s" % async_call.state, extra=dict(data=async_call.__dict__)) task_data = copy.copy(async_call.__dict__) # Make the result respond like an AsyncResult (with an Exception) if async_call.state == 'FAILURE': if isinstance(async_call.result, Exception): # Remove it from task_data or it will break serialization del task_data['_result'] else: #Get the exception from the traceback if not supplied err_string = async_call.traceback.split("\n")[-2] # Store it in the result to be processed later async_call._result = SpiffWorkflowCeleryException( err_string) # Persist the EagerResult in the task as celery does not keep it my_task._set_internal_attribute(eager_task_data=task_data) else: async_call = default_app.send_task(self.call, args=args, kwargs=kwargs) LOG.debug("'%s' called: %s" % (self.call, async_call.task_id)) my_task._set_internal_attribute(task_id=async_call.task_id) my_task.async_call = async_call
def _send_call(self, my_task): """Sends Celery asynchronous call and stores async call information for retrieval laster""" arg, kwargs = None, None if self.args: args = eval_args(self.args, my_task) if self.kwargs: kwargs = eval_kwargs(self.kwargs, my_task) LOG.debug("%s (task id %s) calling %s" % (self.name, my_task.id, self.call), extra=dict(data=dict(args=args, kwargs=kwargs))) if default_app.conf.get("CELERY_ALWAYS_EAGER", False) is True: LOG.debug("Making synchronous call to '%s'" % self.call) if args is None: args = [] if kwargs is None: kwargs = {} # Load the celery task mod = __import__(self.call.split('.')[0]) components = self.call.split('.') for comp in components[1:-1]: mod = getattr(mod, comp) # Call it - This should return an EagerResult async_call = mod.__builtins__['getattr'](mod, components[-1] ).delay(*args, **kwargs) LOG.debug("Call state is %s" % async_call.state, extra=dict(data=async_call.__dict__)) task_data = copy.copy(async_call.__dict__) # Make the result respond like an AsyncResult (with an Exception) if async_call.state == 'FAILURE': if isinstance(async_call.result, Exception): # Remove it from task_data or it will break serialization del task_data['_result'] else: #Get the exception from the traceback if not supplied err_string = async_call.traceback.split("\n")[-2] # Store it in the result to be processed later async_call._result = SpiffWorkflowCeleryException( err_string) # Persist the EagerResult in the task as celery does not keep it my_task._set_internal_attribute(eager_task_data=task_data) else: async_call = default_app.send_task(self.call, args=args, kwargs=kwargs) LOG.debug("'%s' called: %s" % (self.call, async_call.task_id)) my_task._set_internal_attribute(task_id=async_call.task_id) my_task.async_call = async_call