Skip to content

Instantly share code, notes, and snippets.

@kezabelle
Created January 20, 2016 13:24
Show Gist options
  • Save kezabelle/222bed2c6e383d52862a to your computer and use it in GitHub Desktop.
Save kezabelle/222bed2c6e383d52862a to your computer and use it in GitHub Desktop.
For ND1 in #django IRC.
@periodic_task(crontab(...))
def taskmaster():
acted_on = set()
for x in MyModel.objects.filter(...).iterator():
single_item.delay(model_id=x.pk)
acted_on.add(x.pk)
return acted_on
@task
def single_item(model_id):
try:
obj = MyModel.objects.filter(...).get(pk=model_id)
except ObjectDoesNotExist:
logger.error("oh dear", exc_info=1)
return None
else:
return obj.do_something_or_other()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment