renaming
This commit is contained in:
parent
93b3d4b202
commit
90e735852a
@ -20,18 +20,20 @@ class OperationDispatcherMonitoringDecorator:
|
|||||||
def make_summary_instance(self, op: str):
|
def make_summary_instance(self, op: str):
|
||||||
return Summary(f"{self.naming_policy(op)}_seconds", f"Time spent on {op}.", registry=self.registry)
|
return Summary(f"{self.naming_policy(op)}_seconds", f"Time spent on {op}.", registry=self.registry)
|
||||||
|
|
||||||
def push(self, operation, request):
|
def submit(self, operation, request):
|
||||||
return self.operation_dispatcher.push(operation, request)
|
return self.operation_dispatcher.submit(operation, request)
|
||||||
|
|
||||||
|
def pickup(self, operation):
|
||||||
|
with self.get_monitor(operation):
|
||||||
|
return self.operation_dispatcher.pickup(operation)
|
||||||
|
|
||||||
|
def get_monitor(self, operation):
|
||||||
|
monitor = self.operation2metric.get(operation, None) or self.register_operation(operation)
|
||||||
|
return monitor.time()
|
||||||
|
|
||||||
def register_operation(self, operation):
|
def register_operation(self, operation):
|
||||||
summary = self.make_summary_instance(operation)
|
summary = self.make_summary_instance(operation)
|
||||||
self.operation2metric[operation] = summary
|
self.operation2metric[operation] = summary
|
||||||
return summary
|
return summary
|
||||||
|
|
||||||
def get_monitor(self, operation):
|
|
||||||
monitor = self.operation2metric.get(operation, None) or self.register_operation(operation)
|
|
||||||
return monitor.time()
|
|
||||||
|
|
||||||
def pop(self, operation):
|
|
||||||
with self.get_monitor(operation):
|
|
||||||
return self.operation_dispatcher.pop(operation)
|
|
||||||
|
|||||||
@ -8,7 +8,6 @@ from pyinfra.server.stream.rest import LazyRestProcessor
|
|||||||
|
|
||||||
|
|
||||||
class OperationDispatcher:
|
class OperationDispatcher:
|
||||||
|
|
||||||
def __init__(self, operation2function: Dict[str, QueuedStreamFunction]):
|
def __init__(self, operation2function: Dict[str, QueuedStreamFunction]):
|
||||||
submit_suffixes, pickup_suffixes = zip(*map(juxt(submit_suffix, pickup_suffix), operation2function))
|
submit_suffixes, pickup_suffixes = zip(*map(juxt(submit_suffix, pickup_suffix), operation2function))
|
||||||
processors = starmap(LazyRestProcessor, zip(operation2function.values(), submit_suffixes, pickup_suffixes))
|
processors = starmap(LazyRestProcessor, zip(operation2function.values(), submit_suffixes, pickup_suffixes))
|
||||||
@ -16,13 +15,13 @@ class OperationDispatcher:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@property
|
@property
|
||||||
def pop_suffix(cls):
|
def pickup_suffix(cls):
|
||||||
return pickup_suffix("")
|
return pickup_suffix("")
|
||||||
|
|
||||||
def push(self, operation, request):
|
def submit(self, operation, request):
|
||||||
return self.operation2processor[operation].push(request)
|
return self.operation2processor[operation].push(request)
|
||||||
|
|
||||||
def pop(self, operation):
|
def pickup(self, operation):
|
||||||
return self.operation2processor[operation].pop()
|
return self.operation2processor[operation].pop()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -77,21 +77,21 @@ def __set_up_processing_server(operation2function: Dict[str, QueuedStreamFunctio
|
|||||||
|
|
||||||
@app.route("/<operation>", methods=["POST", "PATCH"])
|
@app.route("/<operation>", methods=["POST", "PATCH"])
|
||||||
def submit(operation):
|
def submit(operation):
|
||||||
return dispatcher.push(operation, request)
|
return dispatcher.submit(operation, request)
|
||||||
|
|
||||||
@app.route("/", methods=["POST", "PATCH"])
|
@app.route("/", methods=["POST", "PATCH"])
|
||||||
def submit_default():
|
def submit_default():
|
||||||
return dispatcher.push("", request)
|
return dispatcher.submit("", request)
|
||||||
|
|
||||||
@app.route("/<operation>", methods=["GET"])
|
@app.route("/<operation>", methods=["GET"])
|
||||||
def pickup(operation):
|
def pickup(operation):
|
||||||
return dispatcher.pop(operation)
|
return dispatcher.pickup(operation)
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
||||||
def naming_policy(op_name: str):
|
def naming_policy(op_name: str):
|
||||||
pop_suffix = OperationDispatcher.pop_suffix
|
pop_suffix = OperationDispatcher.pickup_suffix
|
||||||
prefix = f"redactmanager_{CONFIG.service.name}"
|
prefix = f"redactmanager_{CONFIG.service.name}"
|
||||||
|
|
||||||
op_display_name = op_name.replace(f"_{pop_suffix}", "") if op_name != pop_suffix else "default"
|
op_display_name = op_name.replace(f"_{pop_suffix}", "") if op_name != pop_suffix else "default"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user