I am using MySql as result backend for celery. I want to store program arguments in DB too.
For example:
add.apply_async(args=[num1, num2, user]
In this case I want to store user argument in DB, so that I can query later.
Currently, I return arguments provided which is stored in DB.
def add(num1, num2, user):
return [num1+num2, user]
However when the task is running state, user is not inserted and I am unable to query it in DB. Is there any solution/hack for this?
Are you only using MySql as a result backend, or are you using it for the queue as well (which I wouldn't recommend)? If you're using it for a queue, the args should be in the database as soon as the task has been sent. Otherwise, the task result can't be stored until after the task has finished.
If you need the arguments to be query-able while the task is running, you'll need to manually insert them into a DB table at the start of your task. If you want them to be query-able before the task starts, you'll need to insert them into a DB table right before calling apply_async
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With