Celery: why load ID in task_prerun signal rather than task_received?
#103
Unanswered
grahamlyons
asked this question in
Q&A
Replies: 1 comment 1 reply
-
|
I think |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using this middleware and associated Celery extension and so I've used the function
load_correlation_idsto ensure that the IDs are passed from FastAPI to Celery.I noticed that the IDs would be available in the logs for the task succeeded messages from Celery but not the task received ones, so I changed the signal where the ID gets loaded to
task_receivedinstead oftask_prerun(https://github.com/snok/asgi-correlation-id/blob/57f4e40/asgi_correlation_id/extensions/celery.py#L38).I'm not very familiar with the internal workings of Celery, but is there are reason for using one signal over the other?
Update:
I spent some time investigating this and managed to get fairly† consistent loading of correlation IDs using the following signals:
task_internal_errortask_retrytask_revokedtask_receivedtask_rejectedtask_postruntask_prerunIf anyone has more insight I'd love to hear it.
† the values always seem to be missing for the first task received log message, which looks like it runs before the
task_receivedsignalBeta Was this translation helpful? Give feedback.
All reactions