python - Celery: When and where to use the return value of a .delay() running @task to update DB? -
I am creating a degena app with celery.
I have Once the work is completed, I will have to use the return value (string) to update my PostGrace DB. I'm not sure where should I put the DB update code? What do I do: a) b) What is the correct path right here? You should use the second approach, because the delay method immediately ends so that your work ends Could not wait to do And the return_value variable will be an example, not the value that you wanted to get back from my_task. So if you want to update the DB when you are done, then do this in the work. Alternatively, you can use the on_success handler of the working class: @task which I set a fire on
.delay () . .
return_value = My_task.delay (..) (ORM - DB update code)
my_task.delay (..) # & lt; - Task updates the DB
class MyTask: def run (auto, * args, ** kwargs) : # Your execution code def on_success (auto, retval, task_id, args, kwargs): put retval in #db
Comments
Post a Comment