def __init__(self, rabbitmq_request, rabbitmq_service_context): request_state = specialization.create_state_proto() request_state.ParseFromString(rabbitmq_request.experiments_data) self._service_context = rabbitmq_service_context super(RabbitMQTaskContext, self).__init__( request_state, rabbitmq_request.rpc_info if rabbitmq_request.HasField("rpc_info") else None, rabbitmq_request.trace_info if rabbitmq_request.HasField("trace_info") else None)
def _process_result(result): if result.exception() is not None: return try: state_bin = _get_metadata(result.trailing_metadata(), REQUEST_STATE) if state_bin is not None: request_state = proto_encoding.decode( specialization.create_state_proto(), state_bin) task_context.update_state(request_state) except Exception: logging.exception("Error in handling response")
def task_prerun(task=None, **kwargs): trace_info = None request_state = None if task.request.headers is not None: trace_info = task.request.headers.get(TRACE_INFO) request_state = task.request.headers.get(REQUEST_STATE) if trace_info is None and hasattr(task.request, TRACE_INFO): trace_info = getattr(task.request, TRACE_INFO) if request_state is None and hasattr(task.request, REQUEST_STATE): request_state = getattr(task.request, REQUEST_STATE) if trace_info is not None: trace_info = call_info_pb2.TraceInfo().FromString( b64decode(trace_info)) if request_state is not None: request_state = specialization.create_state_proto().FromString( b64decode(request_state)) servicer.set_current_context( CeleryTaskContext(request_state=request_state, trace_info=trace_info))
def __init__(self, grpc_context): request_state = None state_bin = self._get_metadata(grpc_context, REQUEST_STATE) request_state = proto_encoding.decode( specialization.create_state_proto(), state_bin) rpc_info_bin = self._get_metadata(grpc_context, RPC_INFO) rpc_info = proto_encoding.decode( call_info_pb2.RpcInfo(), rpc_info_bin) if rpc_info_bin is not None else None trace_info_bin = self._get_metadata(grpc_context, TRACE_INFO) trace_info = proto_encoding.decode( call_info_pb2.TraceInfo(), trace_info_bin) if trace_info_bin is not None else None super(GrpcTaskContext, self).__init__(request_state, rpc_info, trace_info) self._grpc_context = grpc_context
def get_or_create_state(self): if self.request_state is None: self.request_state = specialization.create_state_proto() return self.request_state
def get_state(headers): encoded_state = headers.get(HTTP_INTERNAL_STATE_HEADER) return decode_from_base64(specialization.create_state_proto(), encoded_state)