I already trying since 2 days to get celery execute periodic tasks but I don't have any luck at all. Can please somebody help me out. Triggering the task manually works as expected. But if I wait 60 seconds like configured simply nothing happens at the console. I already gone trough the whole documentation, also have written my configs completely from scratch, no luck at all task wont execute by themself :(
Do I have to explicitly define
I'm working with:
init.py:
from __future__ import absolute_import, unicode_literals
# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app
__all__ = ('celery_app',)
default_app_config = 'MyApp.apps.AccountsConfig'
celery.py
from celery import Celery
import environ
from django.conf import settings
import celery
env = environ.Env()
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MyApp.settings")
app = Celery(settings.SITE_NAME)
app.config_from_object('django.conf:settings')
# Load task modules from all registered Django app configs.
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
settings.py
BROKER_URL = 'redis://' + ':' + env.str('REDIS_PWD') + '@' + env.str('REDIS_HOST') + ":" + env.str('REDIS_PORT')
BROKER_TRANSPORT = 'redis'
CELERY_RESULT_BACKEND = 'django-db'
CELERY_TASK_RESULT_EXPIRES = 7200
CELERY_REDIS_HOST = env.str('REDIS_HOST')
REDIS_PWD = env.str('REDIS_PWD')
CELERY_REDIS_PORT = env.str('REDIS_PORT')
CELERY_REDIS_DB = env.str('REDIS_CELERY_DB')
CELERY_CACHE_BACKEND = 'default'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = 'UTC'
CELERYD_TASK_SOFT_TIME_LIMIT = 3600
DJANGO_REDIS_LOG_IGNORED_EXCEPTIONS = True
tasks.py:
@app.on_after_finalize.connect
def app_ready(**kwargs):
"""
Called once after app has been finalized.
"""
sender = kwargs.get('sender')
sender.add_periodic_task(60, self_check_beat.s('Celery Beat self check'))# 1 min.
@app.task(name="Celery Beat self check", ignore_result=False)
def self_check_beat(arg):
return "Celery Self-Check Task says <<HELLO>>"
Any Idea why celery does not trigger the task every 5 minutes?
app.conf.beat_schedule={
"task":"your task",
"schedule":"your schedule"
}
Did you add the above snippet in celery.py file?
https://docs.celeryproject.org/en/stable/userguide/periodic-tasks.html