Celery task has disabled backend until another task (from a different app) is imported

Viewed 140

I'm having a problem with celery, redis backend in a django environment.

When I import a celery task from one file the backend is DisabledBackend, and any calls to delay() hang/block.

However when I import a celery task from another file, the backend is RedisBackend and any calls to delay() work fine.

The weird part is that after importing the second task, the backend of the first task changes to RedisBackend and then works fine.

See example below:

>>> from file1 import task1
>>> task1.backend
<celery.backends.base.DisabledBackend object at 0x7f2bf3582470>

>>> from file2 import task2
>>> task2.backend
<celery.backends.redis.RedisBackend object at 0x7f2bf2bc7668>

# And now the very weird bit, the backend of task1 now is correct
>>> task1.backend
<celery.backends.redis.RedisBackend object at 0x7f2bf2bc7668>

Both tasks are defined using the following construct

from celery import shared_task
@shared_task
def task1():
    # Logic here

from celery import shared_task
@shared_task
def task2():
    # Logic here

I can't seem to find any reason why this might happen.

When I inspect the celery log I see both tasks registered.

- ** ---------- [config]
- ** ---------- .> app:         *redacted*
- ** ---------- .> transport:   redis://localhost:6379//
- ** ---------- .> results:     redis://localhost:6379/
- *** --- * --- .> concurrency: 2 (prefork)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** ----- 
 -------------- [queues]
                .> celery           exchange=celery(direct) key=celery
                

[tasks]
  . file1.task1
  . file2.task2

If anyone has any thoughts on this, they'd be greatly appreciated.

0 Answers
Related