Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does a celery worker acknowledge to RabbitMQ that it has a task?

I might be misunderstanding how this works (which is why I'm asking), but I think when a celery worker consumes a task from RabbitMQ it puts a lock on it -- so to speak -- and then must acknowledge it completed that task onces it's done. So say I have 4 workers which all have the prefetch setting at 1 and queue of 6 tasks which take a long time. Once I start those workers and I run:

rabbitmqctl -q list_queues name messages messages_ready messages_unacknowledged

I'd expect to see something like:

celery  6       2       4

indicating that 4 tasks are running (but not yet acknowledged) and 2 are ready to be consumed.

I think my understanding is wrong because what I actually see is:

celery  2       0       2

So it's as if the acknowledging happens when a message is received by a worker, but before that worker finishes processing that task.

So to sum up, my question is, when does a celery worker acknowledge it has a task? It seems like it's once it receives that task and starts working on it, not when it completes working on it. Can someone confirm?

like image 621
Bialecki Avatar asked Sep 26 '12 04:09

Bialecki


People also ask

How does RabbitMQ work with celery?

Celery requires a solution to send and receive messages; usually, this comes in the form of a separate service called a message broker. In celery, the broker is Redis, RabbitMQ, etc who conveying the message between a client and celery.

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.

What is the difference between celery and RabbitMQ?

Celery is an asynchronous distributed task queue. RabbitMQ is a message broker which implements the Advanced Message Queuing Protocol (AMQP).

Is celery a task queue?

You can integrate Celery to help with that. Celery is a distributed task queue for UNIX systems. It allows you to offload work from your Python app. Once you integrate Celery into your app, you can send time-intensive tasks to Celery's task queue.


1 Answers

This is mentioned in the FAQ, but I can't blame you for not finding it: http://docs.celeryproject.org/en/latest/faq.html#should-i-use-retry-or-acks-late

The default behavior of early ack is there because we don't want to enforce users to write idempotent tasks.

like image 181
asksol Avatar answered Sep 26 '22 03:09

asksol