Why Django celery throws me a key error, not sure why?

Not sure why it throws this key error.

My project/celery.py:

import os
from celery import Celery



# Set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')

app = Celery('project')


app.config_from_object('django.conf:settings', namespace='CELERY')

app.autodiscover_tasks()


@app.task(bind=True)
def debug_task(self):
    print(f'Request: {self.request!r}')

my project/init.py:


from .celery import app as celery_app

__all__ = ('celery_app',)

My app/tasks.py

from celery import shared_task
from celery.schedules import crontab
from project.celery import app


@shared_task
def my_test():
   

    print('Celery from task says Hi')

    
app.conf.beat_schedule = {
    'my-task-every-2-minutes': {
        'task': 'my_test',
        'schedule': crontab(minute='*/1'),
    },
}


when I run the command: celery -A project beat -l info

I can see the trigger every 1 min there

  • [2022-12-22 12:38:00,005: INFO/MainProcess] Scheduler: Sending due task my-task-every-2-minutes (celery_app.my_test)

when running celery -A project worker -l info

and triggers sends info I get KeyError: my_test

It seems that it cannot find the task with that key

but from my info everything running fine :


 -------------- celery@192.168.1.131 v5.2.7 (dawn-chorus)
--- ***** ----- 
-- ******* ---- macOS-10.13.6-x86_64-i386-64bit 2022-12-22 12:43:22
- *** --- * --- 
- ** ---------- [config]
- ** ---------- .> app:         project:0x10c757610
- ** ---------- .> transport:   redis://localhost:6379//
- ** ---------- .> results:     redis://localhost:6379/
- *** --- * --- .> concurrency: 4 (prefork)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** ----- 
 -------------- [queues]
                .> celery           exchange=celery(direct) key=celery
                

[tasks]
  . project.celery.debug_task
  . user_statistic_status.tasks.my_test

Back to Top