0

I am working on set up some celery queues for process some tasks. Each task hashes a value and send this task to a delicate queue based on hashed value. What I want to achieve is, to make sure messages in one celery queue can be executed sequentially.

Task looks like this

@app.task(
    acks_late=True,
    autoretry_for=(OperationalError,),
    max_retries=5,
    retry_backoff=True,
    retry_backoff_max=1,
)
def handle_a_task(task):
    # do something

Get a dedicated celery queue

def get_queue(task_value):
    return md5(task_value)

Send task to the queue

queue = get_queue()
handle_a_task.apply_async(
    kwargs={
        "task": {"id": 123},
    },
    queue=queue,
)

In production, there are multiple celery workers. I've seen these workers would take messages from the same queue and process at the same time. What can I do to make messages in one celery queue get processed in order?

I've tried to do celery worker --prefetch-multiplier=1, but it doesn't work.

2
  • this might be helpful stackoverflow.com/questions/63933550/… Commented Dec 12, 2022 at 23:18
  • Why do you even need a distributed task queue then? Celery is used to distribute the tasks among workers so that they could be executed in parallel. If all you want is sequential execution, why do you even need multiple workers? Commented Feb 17, 2023 at 10:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.