Skip to content

Commit

Permalink
Fix exception when using task decorated with bind_callback_meta passi…
Browse files Browse the repository at this point in the history
…ng no callback task.
  • Loading branch information
debonzi-geru committed Sep 26, 2017
1 parent 5d071b9 commit 6da92aa
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions crossover/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,33 @@ def _build_callback(task):

def callback(auto_callback=False, bind_callback_meta=False):
def _executor(func):
def wrapped(*args, **kwargs):
def wrapped(**kwargs):
if 'callback' in kwargs:
_callback = kwargs.pop('callback')
if auto_callback:
return CallBack(_callback)(result=func(**kwargs))
CallBack(_callback)(result=func(**kwargs))
elif bind_callback_meta:
func(_callback, **kwargs)
else:
func(**kwargs)
return
func(**kwargs)
if bind_callback_meta: # and not 'callback' in kwargs
func(None, **kwargs)
else:
func(**kwargs)
return wrapped
return _executor


class CallBack(object):
def __init__(self, callback_data):
self.requester = _Requester(callback_data.get('broker'), callback_data.get('task'))
self.requester = None
if callback_data:
self.requester = _Requester(callback_data.get('broker'), callback_data.get('task'))

def __call__(self, *args, **kwargs):
self.requester(*args, **kwargs)
if self.requester:
self.requester(*args, **kwargs)


class _Requester(object):
Expand Down

0 comments on commit 6da92aa

Please sign in to comment.