Skip to content
This repository has been archived by the owner on Aug 10, 2024. It is now read-only.

Commit

Permalink
feat: improve celery stability
Browse files Browse the repository at this point in the history
  • Loading branch information
bwdmonkey committed Jan 27, 2024
1 parent d2abb22 commit 6ac477a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging

from celery.exceptions import TimeoutError
from celery.result import AsyncResult
# from celery.result import AsyncResult
from celery.states import FAILURE, PENDING, SUCCESS
from django.contrib.auth.decorators import login_required
from django.core import serializers
Expand All @@ -26,6 +26,7 @@
from app.worker.tasks import receiptor
from app.worker.tasks.exporter import exporter
from app.worker.tasks.importers import historical_data_importer
from reboot.celery import app

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -121,7 +122,7 @@ def poll_state(request: HttpRequest):
request=request,
err_msg="The task_id query parameter of the request was omitted.")

task = AsyncResult(task_id)
task = app.AsyncResult(task_id)
res = JsonResponse(_poll_state(PENDING, 0, 200))
if task.state == FAILURE or task.failed():
res = JsonResponse(_poll_state(FAILURE, 0, 400))
Expand All @@ -146,7 +147,7 @@ def download_file(request: HttpRequest):
while (attempts < ATTEMPT_LIMIT):
try:
attempts += 1
task = AsyncResult(task_id)
task = app.AsyncResult(task_id)
result = task.get(timeout=0.5 * attempts)
print(f"{task} {task_name} success #{attempts}: {result}")
break
Expand Down

0 comments on commit 6ac477a

Please sign in to comment.