タスクはDBテーブルbackground_task
に挿入され、タスクが完了すると、タスクはbackground_task
テーブルからbackground_task_completedtask
テーブルに移動されます。この情報を使用して、すべての/特定のタスクのステータスを取得するビューを作成できます。
例:最後に
from background_task.models import Task
from background_task.models_completed import CompletedTask
from datetime import datetime
from django.utils import timezone
def get_status(request):
now = timezone.now()
# pending tasks will have `run_at` column greater than current time.
# Similar for running tasks, it shall be
# greater than or equal to `locked_at` column.
# Running tasks won't work with SQLite DB,
# because of concurrency issues in SQLite.
pending_tasks_qs = Task.objects.filter(run_at__gt=now)
running_tasks_qs = Task.objects.filter(locked_at__gte=now)
# Completed tasks goes in `CompletedTask` model.
# I have picked all, you can choose to filter based on what you want.
completed_tasks_qs = CompletedTask.objects.all()
# main logic here to return this as a response.
# just for test
print (pending_tasks_qs, running_tasks_qs, completed_tasks_qs)
return HttpResponse("ok")
、urlpatternsに、このビューを登録し、状態を確認してください。