Skip to content

Commit

Permalink
Always return a float to ensure it can be JSON-serialized
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergi Chisvert committed Dec 31, 2018
1 parent bcf9aab commit bd1712e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions celery_progress/backend.py
@@ -1,7 +1,7 @@
from abc import ABCMeta, abstractmethod
from celery.result import AsyncResult
from decimal import Decimal

from celery.result import AsyncResult

PROGRESS_STATE = 'PROGRESS'

Expand All @@ -26,7 +26,10 @@ def __init__(self, task):
self.task = task

def set_progress(self, current, total):
percent = round((Decimal(current) / Decimal(total)) * Decimal(100), 2) if total > 0 else 0
percent = 0
if total > 0:
percent = (Decimal(current) / Decimal(total)) * Decimal(100)
percent = float(round(percent, 2))
self.task.update_state(
state=PROGRESS_STATE,
meta={
Expand Down Expand Up @@ -72,11 +75,11 @@ def _get_completed_progress():
'percent': 100,
}


def _get_unknown_progress():
{
return {
'current': 0,
'total': 100,
'percent': 0,
}


0 comments on commit bd1712e

Please sign in to comment.