[Fixed]-My Celery task is executing but it does not execute in a worker


generateCodes.apply_async(args=[product_id, amount_to_gen])

If you run it like generateCodes(..) it will run it as a normal blocking method.


When you call generateCodes(product_id, amount_to_gen), you are bypassing Celery’s distributed facilities.

For the sake of convenience, Celery defines its task object so that simply calling the task like you do will just call the task, just like you call any function in Python. This is described here:

calling (__call__)

Applying an object supporting the calling API (e.g. add(2, 2)) means that the task will be executed in the current process, and not by a worker (a message will not be sent).

Note how it says "not by a worker". That’s your problem. You’d have to call generateCodes.apply_async(product_id, amount_to_gen) to have your task executed by a worker.


Leave a comment