title: Modifying Celery beat schedule shelve database
body: <p>I'm trying to schedule periodic tasks at runtime in Celery.</p>
  
  <p>Here is an <a href="https://stackoverflow.com/questions/10194975/how-to-dynamically-add-remove-periodic-tasks-to-celery-celerybeat">older question</a> that is relevant. <a href="https://stackoverflow.com/a/55603127/4997836">One of the answers</a> in that question mentions that it is now possible to add tasks during runtime since Celery version 4.1.0 (I'm using 4.3.0) but I am not able to achieve that.</p>
  
  <p>I'm modifying the shelve database while the Celery beat is running (or even when it's not running). Here's the code doing that:</p>
  
  <pre class="lang-py prettyprint-override"><code>import shelve
  from celery.beat import ScheduleEntry
  from celery.schedules import schedule
  
  s = schedule(5, app=app)
  entry = ScheduleEntry("Test Task", "proj.tasks.my_task", args=("arg1", "arg2"), schedule=s)
  db = shelve.open("celerybeat-schedule", writeback=True)
  db["entries"]["Test Task"] = entry
  db.close()
  
  </code></pre>
  
  <p>This is stored in the shelve file successfully. Here's the <code>entries</code> field that shelve file:</p>
  
  <pre><code>{'Test Task': &lt;ScheduleEntry: Test Task proj.tasks.my_task('arg1', 'arg2') &lt;freq: 5.00 seconds&gt;}
  </code></pre>
  
  <p>But as soon as the celery beat starts, it over-writes this file and makes <code>entries</code> field an empty <code>dict</code>. Am I missing something? Or this is not possible without using Django or similar scheduler?</p>