Skip to content

Instantly share code, notes, and snippets.

@phblj
phblj / schedulers.py
Last active July 11, 2023 13:00
SingleRunScheduler to remove SPOF of lone celerybeat server. Sorry it's a bit disjoint-- this is pulled out from our codebase, which has a pretty big chunk of custom orm in it
def get_last_run(task_name):
task = db.scheduled_tasks.find_one({'name': task_name})
if task is None:
last_run = time.time()
# race condition possible, but this only happens at first run
db.scheduled_tasks.update(
{
'name': task_name
},