Reputation: 2791
Using Celery 4.1.0
I'm trying to use Celery signals.
When using @task_success
I'm trying to read the parameters I'm supposed to get and they're all None.
This is the signal:
@task_success.connect()
def task_succeeded(result, sender=None, task_id=None, task=None, **kwargs):
print("result: " + str(result))
print("task_id: " + str(task_id))
print("task: " + str(task))
print("sender: " + str(sender))
print("request_id:" + sender.request.id)
The signal does get triggered and I see some printing, but seems like all the parameters' values are None. Any idea why?
Upvotes: 1
Views: 2315
Reputation: 11
@signals.task_success.connect
def task_success_handler(sender=None, result=None,**kwargs):
# Extract information from the result, such as task ID or any relevant data
task_id = sender.request.id
result = AsyncResult(task_id, app=celery)
state = result.state
status = result.status
print('\n\n Sucess task Id', task_id)
print('\n\n Sucess task state', state)
print('\n\n Sucess task status', status)
print('\n\n\n sucesscalled')
Above code worked for me
Upvotes: 1
Reputation: 5658
Reading the documentation for signals, task_success
only accepts two params: sender
and result
.
sender
is the current Task
while result
is the current result of the task execution.
So, in your example, you are trying to read some params that are not defined and result
and sender
are also swapped.
P.D.: I'm answering quite late to this question, but I came across this while searching for task_success
in google. Maybe will help someone in the future.
Upvotes: 4