From 90e735852af2f86e35be845fabf28494de952edb Mon Sep 17 00:00:00 2001 From: Matthias Bisping Date: Wed, 29 Jun 2022 13:47:08 +0200 Subject: [PATCH] renaming --- pyinfra/server/monitoring.py | 18 ++++++++++-------- pyinfra/server/operation_dispatcher.py | 7 +++---- pyinfra/server/server.py | 8 ++++---- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/pyinfra/server/monitoring.py b/pyinfra/server/monitoring.py index 1122461..42d1cf8 100644 --- a/pyinfra/server/monitoring.py +++ b/pyinfra/server/monitoring.py @@ -20,18 +20,20 @@ class OperationDispatcherMonitoringDecorator: def make_summary_instance(self, op: str): return Summary(f"{self.naming_policy(op)}_seconds", f"Time spent on {op}.", registry=self.registry) - def push(self, operation, request): - return self.operation_dispatcher.push(operation, request) + def submit(self, 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): summary = self.make_summary_instance(operation) self.operation2metric[operation] = 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) diff --git a/pyinfra/server/operation_dispatcher.py b/pyinfra/server/operation_dispatcher.py index 90f175d..e885a2e 100644 --- a/pyinfra/server/operation_dispatcher.py +++ b/pyinfra/server/operation_dispatcher.py @@ -8,7 +8,6 @@ from pyinfra.server.stream.rest import LazyRestProcessor class OperationDispatcher: - def __init__(self, operation2function: Dict[str, QueuedStreamFunction]): submit_suffixes, pickup_suffixes = zip(*map(juxt(submit_suffix, pickup_suffix), operation2function)) processors = starmap(LazyRestProcessor, zip(operation2function.values(), submit_suffixes, pickup_suffixes)) @@ -16,13 +15,13 @@ class OperationDispatcher: @classmethod @property - def pop_suffix(cls): + def pickup_suffix(cls): return pickup_suffix("") - def push(self, operation, request): + def submit(self, operation, request): return self.operation2processor[operation].push(request) - def pop(self, operation): + def pickup(self, operation): return self.operation2processor[operation].pop() diff --git a/pyinfra/server/server.py b/pyinfra/server/server.py index 5be345f..68fb804 100644 --- a/pyinfra/server/server.py +++ b/pyinfra/server/server.py @@ -77,21 +77,21 @@ def __set_up_processing_server(operation2function: Dict[str, QueuedStreamFunctio @app.route("/", methods=["POST", "PATCH"]) def submit(operation): - return dispatcher.push(operation, request) + return dispatcher.submit(operation, request) @app.route("/", methods=["POST", "PATCH"]) def submit_default(): - return dispatcher.push("", request) + return dispatcher.submit("", request) @app.route("/", methods=["GET"]) def pickup(operation): - return dispatcher.pop(operation) + return dispatcher.pickup(operation) return app def naming_policy(op_name: str): - pop_suffix = OperationDispatcher.pop_suffix + pop_suffix = OperationDispatcher.pickup_suffix prefix = f"redactmanager_{CONFIG.service.name}" op_display_name = op_name.replace(f"_{pop_suffix}", "") if op_name != pop_suffix else "default"