Skip to content

Commit

Permalink
Merge pull request #29 from Distributive-Network/feature/deserialize-…
Browse files Browse the repository at this point in the history
…job-event-callback-parameters

Deserialize Job Event Params
  • Loading branch information
wiwichips authored Oct 15, 2024
2 parents a9d5969 + dfe1623 commit 9d5cb70
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions dcp/api/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,27 @@ def wait(self):
return dry.aio.blockify(self._wait)()

def on(self, *args):
# deserialize job on event parameters before passing them to user defined callback
def cb_deserialize_wrapper(callback):
def new_cb(*inner_args):
new_args = []
for arg in inner_args:
if isinstance(arg, dict):
for key in arg:
arg[key] = deserialize(arg[key], self.serializers)
new_args.append(deserialize(arg, self.serializers))
return callback(*new_args)
return new_cb

if len(args) > 1 and callable(args[1]):
event_name = args[0]
event_cb = args[1]
event_cb = cb_deserialize_wrapper(args[1])
self.js_ref.on(event_name, event_cb)
else:
event_name = args[0]
def decorator(fn):
self.js_ref.on(event_name, fn)
event_cb = cb_deserialize_wrapper(fn)
self.js_ref.on(event_name, event_cb)
return decorator
return Job

0 comments on commit 9d5cb70

Please sign in to comment.