title: Celery beat schedule, schedule to run on load then on interval
body: <p>I am trying to figure out how to configure a periodic task in celery to be scheduled to run on load regardless of interval.</p>
  
  <p>For example,</p>
  
  <pre><code>beat_schedule = {
      'my-task': {
          'task': 'module.my_task',
          'schedule': 60.0,
      },
  }
  </code></pre>
  
  <p>will wait 60 seconds after the beat is started to run for the first time.</p>
  
  <p>This is problematic for a longer interval, such as an hour, that can do work that is immediately valuable but is not needed "fresh" at shorter intervals.</p>
  
  <p>This <a href="https://stackoverflow.com/questions/28961517/celery-beat-schedule-run-task-instantly-when-start-celery-beat">question</a> addresses this issue but neither of the answers are satisfactory:</p>
  
  <ol>
  <li><p>Adding startup lag for the task to be en-queued is both undesirable performance-wise and bad for maintainability since the initial run and schedule are now separated.</p></li>
  <li><p>Re-implementing the schedule within the task is bad for maintainability.</p></li>
  </ol>
  
  <p>This seems to me something that should be obvious, so I am quite surprised that that SO question is all I can find on the matter. I am unable to figure this out from the docs and the celery github issues so I wonder if I am missing something obvious.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>There seems to be more to the story here, because after trying a different task with an hour interval, it ran immediately as the project celery is started.</p>
  
  <p>If I stop and clear the queue with <code>celery purge -A proj -f</code> then start celery again, the task does not run within the heartbeat interval. This would makes sense because the worker handles the messages but beat has its own schedule record <code>celerybeat-schedule</code> which would be unaffected by the purge.</p>
  
  <p>If I delete <code>celerybeat-schedule</code> and restart beat the task still does not run. Starting celery beat with a non-default schedule db location also does not cause the task to run. The next time the task runs is one hour from the time I started the new beat (14:59) <em>not</em> one hour from the first start time of the task (13:47).</p>
  
  <p>There seems to be some state that is not documented well or is unknown that is the basis of this issue. My question can also be stated as: <strong>how do you force beat to clear its record of last runs?</strong>. </p>
  
  <p>I am also concerned that while running the worker and beat, running <code>celery -A proj inspect scheduled</code> gives <code>- empty -</code> but presumably the task had to be scheduled at some point because it gets run.</p>