diff --git a/celery_progress/backend.py b/celery_progress/backend.py index bf3cbd1..9cc1fbe 100644 --- a/celery_progress/backend.py +++ b/celery_progress/backend.py @@ -60,56 +60,59 @@ def __init__(self, result): self.result = result def get_info(self): - response = {'state': self.result.state} - if self.result.state in ['SUCCESS', 'FAILURE']: + task_meta = self.result._get_task_meta() + state = task_meta["status"] + info = task_meta["result"] + response = {'state': state} + if state in ['SUCCESS', 'FAILURE']: success = self.result.successful() with allow_join_result(): response.update({ 'complete': True, 'success': success, 'progress': _get_completed_progress(), - 'result': self.result.get(self.result.id) if success else str(self.result.info), + 'result': self.result.get(self.result.id) if success else str(info), }) - elif self.result.state in ['RETRY', 'REVOKED']: - if self.result.state == 'RETRY': - retry = self.result.info + elif state in ['RETRY', 'REVOKED']: + if state == 'RETRY': + retry = info when = str(retry.when) if isinstance(retry.when, datetime.datetime) else str( datetime.datetime.now() + datetime.timedelta(seconds=retry.when)) result = {'when': when, 'message': retry.message or str(retry.exc)} else: - result = 'Task ' + str(self.result.info) + result = 'Task ' + str(info) response.update({ 'complete': True, 'success': False, 'progress': _get_completed_progress(), 'result': result, }) - elif self.result.state == 'IGNORED': + elif state == 'IGNORED': response.update({ 'complete': True, 'success': None, 'progress': _get_completed_progress(), - 'result': str(self.result.info) + 'result': str(info) }) - elif self.result.state == PROGRESS_STATE: + elif state == PROGRESS_STATE: response.update({ 'complete': False, 'success': None, - 'progress': self.result.info, + 'progress': info, }) - elif self.result.state in ['PENDING', 'STARTED']: + elif state in ['PENDING', 'STARTED']: response.update({ 'complete': False, 'success': None, - 'progress': _get_unknown_progress(self.result.state), + 'progress': _get_unknown_progress(state), }) else: - logger.error('Task %s has unknown state %s with metadata %s', self.result.id, self.result.state, self.result.info) + logger.error('Task %s has unknown state %s with metadata %s', self.result.id, state, info) response.update({ 'complete': True, 'success': False, - 'progress': _get_unknown_progress(self.result.state), - 'result': 'Unknown state {}'.format(self.result.state), + 'progress': _get_unknown_progress(state), + 'result': 'Unknown state {}'.format(state), }) return response