@celery_app.task(base=WooeyTask)<EOL>def cleanup_dead_jobs():
from .models import WooeyJob<EOL>inspect = celery_app.control.inspect()<EOL>active_tasks = {task['<STR_LIT:id>'] for worker, tasks in six.iteritems(inspect.active()) for task in tasks}<EOL>active_jobs = WooeyJob.objects.filter(status=WooeyJob.RUNNING)<EOL>to_disable = set()<EOL>for job in active_jobs:<EOL><INDENT>if job.celery_id not in active_tasks:<EOL><INDENT>to_disable.add(job.pk)<EOL><DEDENT><DEDENT>WooeyJob.objects.filter(pk__in=to_disable).update(status=WooeyJob.FAILED)<EOL>
This cleans up jobs that have been marked as ran, but are not queue'd in celery. It is meant
to cleanup jobs that have been lost due to a server crash or some other reason a job is
in limbo.