Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Celery - Having sequential tasks rather than concurrent?

I have a few tasks which use the Amazon API which is limited to 1 req/second.

Therefore I would like to group up tasks which use the Amazon API and have them lined up in a sequential queue.

All I've figured out is how to associate queues to each task. But no idea on how to remove concurrency in a specific queue.

Any ideas?

Thanks a lot! :)

like image 220
RadiantHex Avatar asked Nov 02 '25 05:11

RadiantHex


1 Answers

Single worker consuming from a queue with concurrency equals to one ensures that the tasks will be processed in sequential order. In other words you can create a special queue and run only one celery worker with concurrency equals to one:

celery -A tasks worker -Q amazon_queue -c 1

And submit tasks to that queue:

tasks.add.apply_async(args=[1,2], kwargs={}, queue='amazon_queue')

Or use automatic routing for certain task types.

like image 170
mher Avatar answered Nov 03 '25 22:11

mher



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!