Created
January 20, 2016 13:24
-
-
Save kezabelle/222bed2c6e383d52862a to your computer and use it in GitHub Desktop.
For ND1 in #django IRC.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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