Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run celery task without workers

How to run all celery tasks without workers, I mean call directly? I can call task with TaskName.run(), but I want to write this in configurations, so how to make it?

like image 575
Dauren Chapaev Avatar asked Sep 16 '16 03:09

Dauren Chapaev


1 Answers

Just set the CELERY_ALWAYS_EAGER settings to true, this will force celery not to queue the tasks and run them synchronously in the current process.

If you want to be able to do it per specific task, you can run them with apply() or run() as you mentioned, instead of running them with apply_async() or delay().

So tl;dr:

CELERY_ALWAYS_EAGER = True
# The following two would do and act the same, processing synchronously
my_task.run() 
my_task.delay()

But

CELERY_ALWAYS_EAGER = False
# These two won't be the same anymore.
my_task.run() # Runs synchronously
my_task.delay() # Passed to the queue and runs Asynchronously, in another process
like image 113
SpiXel Avatar answered Nov 09 '22 16:11

SpiXel