How to point to a celery beat periodic task inside the upper level folder?
I want to make a periodic task with Django and Celery. I have configured the celery in my project.
The project structure looks like this:
├── apps
│ ├── laws
└──tasks
└──periodic.py # the task is in this file
├── config
│ ├── celery.py
│ ├── settings
└── base.py # CELERY_BEAT_SCHEDULE defined in this file
content of base.py settings file:
CELERY_BEAT_SCHEDULE = {
"sample_task": {
"task": "apps.laws.tasks.periodic.SampleTask", # the problem is in the line
"schedule": crontab(minute="*/1"),
},
}
The task on periodic.py:
class LawAmendmentTask(Task):
def run(self, operation, *args, **kwargs):
logger.info("The sample task in running...")
How can I define the route of the task correctly?
I solved it. instead of the route, just put the name of the task in settings:
CELERY_BEAT_SCHEDULE = {
"laws.sample_task": {
"task": "laws.sample_task", # put the name here.
"schedule": crontab(minute="*/1"),
},
}