3

I have a tool that uses Celery and RabbitMQ as the broker to dispatch jobs. In all workers I have a program with two tasks, A y B. I want B task to be executed after A and in the same worker. Should work like this:

  1. User invoke task A.
  2. Task A finalize and calls task B.
  3. Task B finalize and return results to the User.

Is this possible using Celery?

David Moreno García
  • 4,423
  • 8
  • 49
  • 82
  • 2
    `return B()` at the end of `A`? Afaik none of the subtask options guarantee same worker without some very fancy routing setups, and I can't see what the benefit of such a setup would be. – kalhartt Jan 20 '15 at 01:56
  • 1
    I agree with kalharrt, you should avoid having tasks bound to same worker. Otherwise just run b() as suggested. – ant31 Jan 20 '15 at 09:15
  • @kalhartt I need to know what is doing the worker from the dashboard. That is why I have that second task. Also, the second task must be executed in the same flower because use data downloaded by the first task. – David Moreno García Jan 20 '15 at 11:34
  • If you want to keep the data you have downloaded you either mush pass it to the next task or call B() as was suggested. Just because you use the same "worker" doesn't mean it's in the same instance and will have everything stored in local variables. – user2097159 Jan 20 '15 at 12:19
  • @user2097159 I download up to 200MB per call so I can't pass it to the next task. I suppose that my only option is to call a loca function as kalhartt said. – David Moreno García Jan 20 '15 at 12:39
  • 1
    @DavidMorenoGarcía If you just want to monitor the status from flower, you can have one task and use custom states [like this](http://celery.readthedocs.org/en/latest/userguide/tasks.html#custom-states) – kalhartt Jan 20 '15 at 19:18
  • @kalhartt it's a good approach. I try that. Thank you. – David Moreno García Jan 20 '15 at 19:29
  • It looks like the answer for your question is here: http://stackoverflow.com/questions/21829868/python-celery-how-to-call-celery-tasks-inside-other-task – acknapp Jun 19 '15 at 18:23

0 Answers0