title: How to dynamically change the schedule of celery beat?
body: <p>I am using Celery 4.3.0. I am trying to update the schedule of celery beat every 5 seconds based on a schedule in a json file, so that when I’m manually editing, adding or deleting scheduled tasks in that json file, the changes are picked up by the celery beat scheduler without restarting it.</p>
  
  <p>What I tried is creating a task that update this schedule by updating <code>app.conf['CELERYBEAT_SCHEDULE']</code>. The task successfully runs every 5 seconds but celery beat doesn’t update to the new schedule, even though I set <code>beat_max_loop_interval</code> to 1 sec.</p>
  
  <p><em>tasks.py</em></p>
  
  <pre><code>from celery import Celery
  
  app = Celery("tasks", backend='redis://', broker='redis://')
  app.config_from_object('celeryconfig')
  
  @app.task
  def hello_world():
      return "Hello World!"
  
  @app.task
  def update_schedule():
      with open("path_to_scheduler.json", "r") as f:
          app.conf['CELERYBEAT_SCHEDULE'] = json.load(f)
  </code></pre>
  
  <p><em>celeryconfig.py</em></p>
  
  <pre><code>beat_max_loop_interval = 1  # Maximum number of seconds beat can sleep between checking the schedule
  
  beat_schedule = {
      "greet-every-10-seconds": {
          "task": "tasks.hello_world",
          "schedule": 10.0
      },
      'update_schedule': {
          'task': 'tasks.update_schedule',
          'schedule': 5.0
      },
  }
  </code></pre>
  
  <p><em>schedule.json</em></p>
  
  <pre><code>{
    "greet-every-2-seconds": {
          "task": "tasks.hello_world",
          "schedule": 2.0
      },
    "update_schedule": {
      "task": "tasks.update_schedule",
      "schedule": 5.0
    }
  }
  </code></pre>
  
  <p>Any help would be appreciated. If you know a better way to reload the beat schedule from a file I’m also keen to hear it.</p>