I want a user of my application to start / stop periodic crontab style tasks using the Celery effect. I'm starting Celery right now with
venv/bin/celery worker -A celery_worker.celery
I got a Celery Beat with this simple example:
@celery.task def add(x, y): return x + y
in my configuration file:
CELERYBEAT_SCHEDULE = { 'add-every-30-seconds': { 'task': 'app.email.add', 'schedule': timedelta(seconds=30), 'args': (16, 16) }, } CELERY_TIMEZONE = 'UTC'
then I start a celery worker with
celery -A celery_worker.celery beat -s ~/Documents/cesco-automation/power/celerybeat-schedule
And it works great! But I need more control over the schedule.
Also in my application shell I can do this.
>>>add.apply_async([80,800],countdown=30) >>> from datetime import datetime, timedelta >>> tomorrow = datetime.now() + timedelta(days=1) >>> add.apply_async(args=[10, 10], eta=tomorrow)
It's great, but I'm developing a home automation application, so I also need to stop the tasks. How to do it?
I also found a link mentioning the django custom scheduler classes. This is exactly what I need. On Celery docs , it mentions the -S flag, but I don't know how to properly add a class to my Flask application. How can I use it with Flask?
Do I need a Celery Beat? Is there another option, another crontab? The crontab seems not sharp enough.