Created
October 28, 2011 22:54
-
-
Save jdunck/1323787 to your computer and use it in GitHub Desktop.
Clean up defunct celery PeriodicTask entries
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
from djcelery.models import PeriodicTask | |
from django.utils import importlib | |
bad_tasks = [] | |
good_tasks = [] | |
for pt in PeriodicTask.objects.iterator(): | |
path_name, task_name = pt.task.rsplit('.', 1) | |
try: | |
module = importlib.import_module(path_name) | |
except ImportError: | |
bad_tasks.append(pt) | |
continue | |
if not hasattr(module, task_name): | |
bad_tasks.append(pt) | |
continue | |
good_tasks.append(pt) | |
########## | |
Review bad_tasks before proceeding: | |
########## | |
for t in bad_tasks: | |
t.delete() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment