def task_webhook(fun):
 @wraps(fun)
 def _inner(*args, **kwargs):
  try:
   retval = fun(*args, **kwargs)
  except Exception as exc:
   response = {'status': 'failure', 'reason': safe_repr(exc)}
  else:
   response = {'status': 'success', 'retval': retval}
  return JsonResponse(response)
 return _inner

def task_webhook ( fun ) : @ wraps ( fun ) def _inner ( * args , ** kwargs ) : try : retval = fun ( * args , ** kwargs ) except Exception as exc : response = { 'status' : 'failure' , 'reason' : safe_repr ( exc ) } else : response = { 'status' : 'success' , 'retval' : retval } return JsonResponse ( response ) return _inner
decorator turning a function into a task webhook .