Celery beat doesn't run periodic task

I have task

class BasecrmSync(PeriodicTask):
run_every = schedules.crontab(minute='*/1')

def run(self, **kwargs):
    bc = basecrm.Client(access_token=settings.BASECRM_AUTH_TOKEN)
    sync = basecrm.Sync(client=bc, device_uuid=settings.BASECRM_DEVICE_UUID)
    sync.fetch(synchronize)

And celery config with db broker

CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend'
BROKER_URL = 'django://'
CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'

I run

celery -A renuval_api worker -B --loglevel=debug

But it doesn't run task... Also I've tried run by

python3 manage.py celery worker --loglevel=DEBUG  -E -B -c 1 --settings=renuval_api.settings.local

But It uses amqp transport and I can't understand why.

Upvotes: 1

Views: 2650

Answers (1)

Guerry
Guerry

Reputation: 739

I run a separate process for the beat function itself. I could never get periodic tasks to fire otherwise. Of course, I may have this completely wrong, but it works for me and has for some time.

For example, I have the celery worker with its app running in one process:

celery worker --app=celeryapp:app -l info --logfile="/var/log/celery/worker.log"

And I have the beat pointed to the same app in its own process:

celery --app=celeryapp:app beat

They are pointed at the same app and settings, and beat fires off the task which the worker picks up and does. This app is in the same code tree as my Django apps, but the processes are not running in Django. Perhaps you could run something like:

python3 manage.py celery beat --loglevel=DEBUG  -E -B -c 1 --settings=renuval_api.settings.local

I hope that helps.

Upvotes: 1

Related Questions