Skip to content

Commit

Permalink
Support async_ hook param in addition to async
Browse files Browse the repository at this point in the history
  • Loading branch information
cheungpat authored and carmenlau committed Jun 11, 2018
1 parent feccd57 commit ff23dc9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions skygear/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ def register_hook(self, name, func, *args, **kwargs):
raise ValueError("trigger is required for hook")
kwargs['name'] = name

if 'async_' in kwargs:
kwargs['async'] = kwargs.pop('async_')

if name in self.func_map['hook']:
log.warning("Replacing previously registered hook '%s'.", name)

Expand Down
2 changes: 1 addition & 1 deletion skygear/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def some_lambda_func():
'message': 'Some message being returned'
}
@skygear.after_save('some_record', async=True)
@skygear.after_save('some_record', async_=True)
def some_record_after_save(record, original_record, db):
return {
'success': True
Expand Down
2 changes: 2 additions & 0 deletions skygear/tests/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def fn():
kwargs = {
'type': 'note',
'trigger': 'beforeSave',
'async_': True,
}
registry = Registry()
registry.register_hook('hook_name', fn, **kwargs)
Expand All @@ -182,6 +183,7 @@ def fn():
assert param_map[0]['name'] == 'hook_name'
assert param_map[0]['type'] == 'note'
assert param_map[0]['trigger'] == 'beforeSave'
assert param_map[0]['async'] is True

def test_register_hook_twice(self):
def fn1():
Expand Down

0 comments on commit ff23dc9

Please sign in to comment.