celery: handle pyramid/pylons context better when running async tasks.
This commit is contained in:
parent
b753a099d7
commit
246f2093bd
2 changed files with 15 additions and 3 deletions
|
|
@ -256,7 +256,7 @@ def request_view(request):
|
|||
except JSONRPCBaseError:
|
||||
raise
|
||||
except Exception:
|
||||
log.exception('Unhandled exception occured on api call: %s', func)
|
||||
log.exception('Unhandled exception occurred on api call: %s', func)
|
||||
return jsonrpc_error(request, retid=request.rpc_id,
|
||||
message='Internal server error')
|
||||
|
||||
|
|
|
|||
|
|
@ -76,6 +76,18 @@ class RhodecodeCeleryTask(Task):
|
|||
|
||||
request = get_current_request()
|
||||
|
||||
if hasattr(request, 'user'):
|
||||
ip_addr = request.user.ip_addr
|
||||
user_id = request.user.user_id
|
||||
elif hasattr(request, 'rpc_params'):
|
||||
# TODO(marcink) remove when migration is finished
|
||||
# api specific call on Pyramid.
|
||||
ip_addr = request.rpc_params['apiuser'].ip_addr
|
||||
user_id = request.rpc_params['apiuser'].user_id
|
||||
else:
|
||||
raise Exception('Unable to fetch data from request: {}'.format(
|
||||
request))
|
||||
|
||||
if request:
|
||||
# we hook into kwargs since it is the only way to pass our data to
|
||||
# the celery worker in celery 2.2
|
||||
|
|
@ -91,8 +103,8 @@ class RhodecodeCeleryTask(Task):
|
|||
'wsgi.url_scheme': request.environ['wsgi.url_scheme'],
|
||||
},
|
||||
'auth_user': {
|
||||
'ip_addr': request.user.ip_addr,
|
||||
'user_id': request.user.user_id
|
||||
'ip_addr': ip_addr,
|
||||
'user_id': user_id
|
||||
},
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue