def _call(self, fn_name, *args, **kwargs):
with transaction.commit_manually():
transaction.commit()
# If the caller specified rcp_timeout then fetch it from the args and remove.
rpc_timeout = kwargs.pop('rpc_timeout', RESPONSE_TIMEOUT)
request_id = uuid.uuid4().__str__()
request = {
'method': fn_name,
'args': args,
'kwargs': kwargs,
'request_id': request_id}
log.debug("Starting rpc: %s, id: %s " % (fn_name, request_id))
log.debug("_call: %s %s %s %s" % (request_id, fn_name, args, kwargs))
rpc_client = RpcClientFactory.get_client(self.__class__.__name__)
result = rpc_client.call(request, rpc_timeout)
if result['exception']:
log.error("ServiceRpcInterface._call: exception %s: %s \ttraceback: %s" % (result['exception'], result['exception_type'], result.get('traceback')))
raise RpcError(result['exception'], result.get('exception_type'), traceback=result.get('traceback'))
else:
# NB: 'result' can be very large, and almost cripple the various logs where
# rpcs are run: http.log, job_scheduler.log, etc.
# If you want to see response result data from rpcs at the INFO level, consider writing
# log messages into the JobSchedulerClient calls. Leaving this in for DEBUG.
if log.getEffectiveLevel() is not logging.DEBUG:
# Truncate message
result100 = str(result)[:100]
if str(result) != result100:
result100 += "..."
result_str = result100
else:
result_str = result
log.debug("Completed rpc: %s, id: %s, result: %s" % (fn_name, request_id, result_str))
return result['result']
评论列表
文章目录