Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interact with celery ongoing task

We have a distributed architecture based on rabbitMQ and Celery. We can launch in parallel multiple tasks without any issue. The scalability is good.

Now we need to control the task remotely: PAUSE, RESUME, CANCEL. The only solution we found is to make in the Celery task a RPC call to another task that replies the command after a DB request. The Celery task and RPC task are not on the same machine and only the RPC task has access to the DB.

Do you have any advice how to improve it and easily communicate with an ongoing task? Thank you

EDIT: In fact we would like to do something like in the picture below. It's easy to do the Blue configuration or the Orange, but we don't know how to do both simultaneously. enter image description here Workers are subscribing to a common Jobs queue and each worker has its own Admin queue declared on an exchange.

EDIT: IF this is not possible with Celery, I'am open to a solution with other frameworks like python-rq.

like image 816
Julio Avatar asked May 27 '15 12:05

Julio


People also ask

How do you call Celery tasks?

If the task isn't registered in the current process you can use send_task() to call the task by name instead. So delay is clearly convenient, but if you want to set additional execution options you have to use apply_async .

How does celery task queue work?

Celery communicates via messages, usually using a broker to mediate between clients and workers. To initiate a task, the Celery client adds a message to the queue, and the broker then delivers that message to a worker. The most commonly used brokers are Redis and RabbitMQ.

Can a celery task call another task?

To answer your opening questions: As of version 2.0, Celery provides an easy way to start tasks from other tasks. What you are calling "secondary tasks" are what it calls "subtasks".


1 Answers

It look like the Control Bus pattern.

For a better scalability and in order to reduce the RPC call, I recommend to reverse the logic. The PAUSE, RESUME, CANCEL command are push to the Celery tasks through a control bus when the state change occurs. The Celery app will store the current state of the Celery app in a store (could be in memory, on the filesystem..). If task states must be kept even after a stop/start of the app, It will involve more work in order to keep both app synchronized (eg. synchronization at startup).

like image 118
Nicolas Labrot Avatar answered Oct 09 '22 12:10

Nicolas Labrot