From ea8db7657f889c41ca776d7a582150e802843557 Mon Sep 17 00:00:00 2001 From: Maxim Podosochnyy <podosochnyy@perx.ru> Date: Wed, 29 Nov 2023 19:09:25 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=20ExtensionService=20=D1=81=20=D1=83=D1=87?= =?UTF-8?q?=D1=91=D1=82=D0=BE=D0=BC=20long=20polling=20=D0=BE=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B0=D1=86=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- perxis/extensions/extension_service.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/perxis/extensions/extension_service.py b/perxis/extensions/extension_service.py index fae7e76..664d11e 100644 --- a/perxis/extensions/extension_service.py +++ b/perxis/extensions/extension_service.py @@ -46,7 +46,11 @@ class OperationMeta: was_finished: bool = False metadata: dict[str, typing.Any] = dataclasses.field(default_factory=dict) - def finish(self, errors: typing.Optional[list[str]] = None): + def mark_cancelled(self): + self.was_finished = True + self.response = "Отменено" + + def mark_finished(self, errors: typing.Optional[list[str]] = None): self.modified_at = datetime.datetime.now() self.was_finished = True self.errors = errors @@ -191,7 +195,7 @@ class ExtensionService( self.result_log("установки", operation_id, request, errors_list) - self.__operations[operation_id].finish(errors_list) + self.__operations[operation_id].mark_finished(errors_list) async def Install(self, request: extension_service_pb2.InstallRequest, context): operation_id = generate_operation_id() @@ -215,7 +219,7 @@ class ExtensionService( self.result_log("удаления", operation_id, request, errors_list) - self.__operations[operation_id].finish(errors_list) + self.__operations[operation_id].mark_finished(errors_list) async def Uninstall(self, request: extension_service_pb2.UninstallRequest, context): operation_id = generate_operation_id() @@ -239,7 +243,7 @@ class ExtensionService( self.result_log("проверки", operation_id, request, errors_list) - self.__operations[operation_id].finish(errors_list) + self.__operations[operation_id].mark_finished(errors_list) async def Check(self, request: extension_service_pb2.CheckRequest, context): operation_id = generate_operation_id() @@ -262,7 +266,7 @@ class ExtensionService( return None async def Get(self, request: operation_service_pb2.GetOperationRequest, context): - operations_meta = self.__operations.get(request.operation_id) + operations_meta = self.get_operation_meta(request.operation_id) if not operations_meta: error_description = "Ошибка проверки операции %s в расширении %s - не найдена" % ( @@ -287,7 +291,7 @@ class ExtensionService( return operations_meta.to_operation() def Cancel(self, request: operation_service_pb2.CancelOperationRequest, context): - operations_meta = self.__operations.get(request.operation_id) + operations_meta = self.get_operation_meta(request.operation_id) if not operations_meta: error_description = "Не удалось удалить операцию %s в расширении %s - не найдена" % ( @@ -306,8 +310,7 @@ class ExtensionService( try: operations_meta.task.cancel() - - operations_meta.response = "Отменено" + operations_meta.mark_cancelled() except Exception as e: error_description = "Во время отмены операции %s расширении %s произошла ошибка %s" % ( request.operation_id, -- GitLab