Skip to content

Commit

Permalink
changes in task manager related to async_deliver_hook
Browse files Browse the repository at this point in the history
  • Loading branch information
jefer94 authored Oct 6, 2023
1 parent b0dbe31 commit 734bf06
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions breathecode/utils/decorators/task.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import datetime
from decimal import Decimal
import inspect
import logging
from typing import Callable
Expand All @@ -16,6 +18,33 @@ class AbortTask(Exception):
pass


def parse_payload(payload: dict):
if not isinstance(payload, dict):
return payload

for key in payload.keys():
# TypeError("string indices must be integers, not 'str'")
if isinstance(payload[key], datetime):
payload[key] = payload[key].isoformat().replace('+00:00', 'Z')

elif isinstance(payload[key], Decimal):
payload[key] = str(payload[key])

elif isinstance(payload[key], list) or isinstance(payload[key], tuple) or isinstance(
payload[key], set):
l = []
for item in payload[key]:
print(item)
l.append(parse_payload(item))

payload[key] = l

elif isinstance(payload[key], dict):
payload[key] = parse_payload(payload[key])

return payload


class Task(object):

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -49,10 +78,10 @@ def __call__(self, function):
def wrapper(*args, **kwargs):
task_module, task_name = self.get_fn_desc(function)
reverse_module, reverse_name = self.get_fn_desc(self.reverse)
arguments = {
arguments = parse_payload({
'args': args[1:] if self.bind else args,
'kwargs': kwargs,
}
})

page = kwargs.get('page', 0)
total_pages = kwargs.get('total_pages', 1)
Expand All @@ -66,6 +95,18 @@ def wrapper(*args, **kwargs):
created = False
if x is None:
created = True
from unittest.mock import call

print(
call(task_module=task_module,
task_name=task_name,
reverse_module=reverse_module,
reverse_name=reverse_name,
arguments=arguments,
status='PENDING',
current_page=page + 1,
total_pages=total_pages,
last_run=last_run))
x = TaskManager.objects.create(task_module=task_module,
task_name=task_name,
reverse_module=reverse_module,
Expand Down

0 comments on commit 734bf06

Please sign in to comment.