-1

I'm using celery and celery-beat without Django and I have a task which needs to modify celery-beat schedule when run.

Now I have the following code (module called celery_tasks):

# __init__.py

from .celery import app as celery_app

__all__ = ['celery_app']

#celery.py

from celery import Celery

import config

celery_config = config.get_celery_config()

app = Celery(
    __name__,
    include=[
        'celery_tasks.tasks',
    ],
)

app.conf.update(celery_config)

# tasks.py

from celery_tasks import celery_app
from celery import shared_task


@shared_task
def start_game():

    celery_app.conf.beat_schedule = {
        'process_round': {
            'task': 'celery_tasks.tasks.process_round',
            'schedule': 5,
        },
    }

I start celery with the following command:

celery worker -A celery_tasks -E -l info --beat

start_game executes and exists normally, but beat process_round task never runs.

How can I force-reload beat schedule (restarting all workers doesn't seem as a good idea)?

pomo_mondreganto
  • 2,028
  • 2
  • 28
  • 56

2 Answers2

2

the problem with normal celery backend when you start the celerybeat process. it will create a config file and write all tasks and schedules in to that file


so it cannot change dynamically you can use the package celerybeat-sqlalchemy-scheduler so you can edit schedule on DB itself so that celerybeat will pickup the new schedule from DB itself

also there is another package celery-redbeat which using redis-server as backend

you can refer this this also

Nakul Narayanan
  • 1,412
  • 13
  • 17
0

Using schedule config also seems bad idea. What if initially process_round task will be active and check if game is not started task just do nothing.