from celery import shared_task from celery.result import AsyncResult from .models import UncloudTask @shared_task def cleanup_tasks(): print("Cleanup time") for task in UncloudTask.objects.all(): print(f"Pruning {task}...") res = AsyncResult(id=str(task.task_id)) if res.ready(): print(res.get()) task.delete()