Dynamically plan a celery removal task using a bulb

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 --loglevel=info 

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.

+6
source share
2 answers

This functionality will be available in Celery ver.4.0. Dynamic task scheduling is supported only in the development version: http://docs.celeryproject.org/en/master/userguide/periodic-tasks.html#beat-entries

+4
source

Despite the fact that we abandoned the flash drive / python for our application. This problem was resolved with a scheduler called Kala . This is simple JSON through the HTTP API that Chronus created, which does the same as Kala, but is a much more reliable and scalable Airbnb solution. His fully linguistic agnostic.

0
source

Source: https://habr.com/ru/post/989488/


All Articles