Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where should you update Celery settings? On the remote worker or sender?

Where should you update celery settings? On the remote worker or the sender?

For example, I have an API using Django and Celery. The API sends remote jobs to my remote workers via a broker (RabbitMQ). The workers are running a python script (not using Django) sometimes these works spawn sub tasks.

I've created celery settings on both sides (sender and worker) i.e. they both need the setting BROKER_URL. However, say I want to add the setting CELERY_ACKS_LATE = True, which end do I add this setting to? Each of the remote workers or the sender (API)?

Both the API and the remote workers connect to the same Broker, each start celery differently. The API creates a celery instance via Django __init__.py and the workers start celery via supervisor i.e. celery -A tasks worker -l info

like image 839
Prometheus Avatar asked Jan 31 '16 18:01

Prometheus


People also ask

What is worker in celery?

Celery worker is a simple, flexible, and reliable distributed system to process vast amounts of messages while providing operations with the tools required to maintain such a system. In this tutorial, we will learn how to implement Celery with Flask and Redis.

How does celery and Redis work?

Celery is a task queue with focus on real-time processing, while also supporting task scheduling. Redis is a message broker. This means it handles the queue of "messages" between Django and Celery. Django is a web framework made for perfectionists with deadlines.

What is celery result backend?

Celery uses a result backend to keep track of the tasks' states. In the previous tutorial, we saw how Celery works and how to integrate it into a Django application. In this tutorial, we are going to use the RPC (RabbitMQ/AMQP) result backend to store and retrieve the states of tasks.


2 Answers

the django celery settings affects only workers running on the django server itself.

if all your workers are remote workers (the way as i do it), then on the sender side all you need is to put the configuration necessary to submit a task to the task queue.

and all the other settings need to be set on the remote workers.

and for the tasks, on the sender side, all i need to do is to define the task signature like this:

@app.task(name='report_task')
def reportTask(self, link):
    pass

then on the worker side, you need to create a new Celery app with the same name and pointing to the same broker; for other celery settings you need to declare them on the remote workers.

and implement the tasks logic on the remote workeres (you can have different tasks logic per worker as long as they have the same task name and the function arguments)

like image 188
Soufiaane Avatar answered Sep 28 '22 02:09

Soufiaane


CELERY_ACKS_LATE = True belongs to worker. It describes if worker should mark the task 'acknowledged' immediately after consuming (before completion) or after completing (late). Both methods have their drawbacks and I think you know what you're doing.

Of course it would be better to have single configuration file for both parties and use it. For example have the common codebase for entire project and after updating the file in VCS and deploy - restart all parties.

But in this case with this particular flag you can restart only workers.

like image 28
baldr Avatar answered Sep 28 '22 01:09

baldr