uncloud-mravi/uncloud/tasks.py

23 lines
595 B
Python
Raw Normal View History

from celery import shared_task
from celery.result import AsyncResult
from .models import UncloudTask
2020-12-20 18:17:03 +00:00
@shared_task(bind=True)
def cleanup_tasks(self):
print(f"Cleanup time from {self}: {self.request.id}")
for task in UncloudTask.objects.all():
print(f"Pruning {task}...")
2020-12-20 18:17:03 +00:00
if str(task.task_id) == str(self.request.id):
print("Skipping myself")
continue
res = AsyncResult(id=str(task.task_id))
2020-12-26 10:22:51 +00:00
print(f"Task {task}: {res.state}")
if res.ready():
print(res.get())
task.delete()
2020-12-26 10:22:51 +00:00
res.forget()