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 @task which I set a fire on .delay () . .

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)

  return_value = My_task.delay (..) (ORM - DB update code)   

b)

  my_task.delay (..) # & lt; - Task updates the DB   

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:

  class MyTask: def run (auto, * args, ** kwargs) : # Your execution code def on_success (auto, retval, task_id, args, kwargs): put retval in #db    

Comments

Popular posts from this blog

c++ - ERROR: cannot open source file x11\xlib.h -

c - What are pthread cancelation points used for? -

c# - Show a huge number of data in DevExpress GridView -