Skip to content

Commit

Permalink
update: make _get_result_meta fn similar as of celery
Browse files Browse the repository at this point in the history
  • Loading branch information
AmitPhulera committed Jun 3, 2022
1 parent bde3eef commit ee7ac53
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions django_celery_results/backends/database.py
Expand Up @@ -54,7 +54,23 @@ def exception_safe_to_retry(self, exc):
return True
return False

def _get_result_meta(self, request, traceback):
def _get_result_meta(
self, result, state, traceback, request, format_date=True, encode=False
):
"""Store return value and status of an executed task."""
content_type, content_encoding, result = self.encode_content(result)
_, _, meta = self.encode_content(
{'children': self.current_task_children(request)}
)

task_props = {
'content_encoding': content_encoding,
'content_type': content_type,
'meta': meta,
'result': result,
'status': state,
'traceback': traceback,
}
extended_props = {
'periodic_task_name': None,
'task_args': None,
Expand Down Expand Up @@ -97,7 +113,8 @@ def _get_result_meta(self, request, traceback):
'worker': getattr(request, 'hostname', None),
})

return extended_props
task_props.update(extended_props)
return task_props

def _store_result(
self,
Expand All @@ -108,27 +125,15 @@ def _store_result(
request=None,
using=None
):
"""Store return value and status of an executed task."""
content_type, content_encoding, result = self.encode_content(result)
_, _, meta = self.encode_content(
{'children': self.current_task_children(request)}

task_props = self._get_result_meta(
result=result, state=status,
traceback=traceback, request=request
)

task_props = {
'content_encoding': content_encoding,
'content_type': content_type,
'meta': meta,
'result': result,
'status': status,
task_props.update({
'task_id': task_id,
'traceback': traceback,
'using': using,
}

task_props.update(
self._get_result_meta(request, traceback, using)
)

})
self.TaskModel._default_manager.store_result(**task_props)
return result

Expand Down

0 comments on commit ee7ac53

Please sign in to comment.