Skip to content

Commit

Permalink
Merge pull request #337 from Terralego/fix_refresh_task_status
Browse files Browse the repository at this point in the history
fix task report state
  • Loading branch information
submarcos authored Aug 30, 2023
2 parents 5c5871b + c69b482 commit 9ba101a
Showing 1 changed file with 1 addition and 13 deletions.
14 changes: 1 addition & 13 deletions project/geosource/mixins.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
from datetime import timedelta

from celery import states
from django.utils.timezone import now
from rest_framework.exceptions import MethodNotAllowed

from project.geosource.tasks import run_model_object_method

from .app_settings import MAX_TASK_RUNTIME


class CeleryCallMethodsMixin:
DONE_STATUSES = ("SUCCESS", "FAILURE", "NEED_SYNC", None)

def update_status(self, task):
self.task_id = task.task_id
self.task_date = now()
Expand All @@ -20,13 +14,7 @@ def update_status(self, task):
@property
def can_sync(self):
"""Property containing a boolean that tell if the state allow to run a sync"""
status = self.get_status()

return status.get("state") in self.DONE_STATUSES or (
status.get("state") not in self.DONE_STATUSES
and self.task_date is not None
and self.task_date < now() - timedelta(hours=MAX_TASK_RUNTIME)
)
return self.status != self.Status.PENDING

def run_async_method(
self,
Expand Down

0 comments on commit 9ba101a

Please sign in to comment.