code: def cleanup_dead_jobs():
      
      from .models import WooeyJob
  
      # Get active tasks from Celery
      inspect = celery_app.control.inspect()
      active_tasks = {task['id'] for worker, tasks in six.iteritems(inspect.active()) for task in tasks}
  
      # find jobs that are marked as running but not present in celery's active tasks
      active_jobs = WooeyJob.objects.filter(status=WooeyJob.RUNNING)
      to_disable = set()
      for job in active_jobs:
          if job.celery_id not in active_tasks:
              to_disable.add(job.pk)
  
      WooeyJob.objects.filter(pk__in=to_disable).update(status=WooeyJob.FAILED)
docs: 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.