Skip to content
Snippets Groups Projects
Commit ea8db765 authored by Podosochnyy Maxim's avatar Podosochnyy Maxim
Browse files

Реализация ExtensionService с учётом long polling операций

parent 3000c27f
No related branches found
No related tags found
1 merge request!61Реализация ExtensionService с учётом long polling операций
...@@ -46,7 +46,11 @@ class OperationMeta: ...@@ -46,7 +46,11 @@ class OperationMeta:
was_finished: bool = False was_finished: bool = False
metadata: dict[str, typing.Any] = dataclasses.field(default_factory=dict) 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.modified_at = datetime.datetime.now()
self.was_finished = True self.was_finished = True
self.errors = errors self.errors = errors
...@@ -191,7 +195,7 @@ class ExtensionService( ...@@ -191,7 +195,7 @@ class ExtensionService(
self.result_log("установки", operation_id, request, errors_list) 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): async def Install(self, request: extension_service_pb2.InstallRequest, context):
operation_id = generate_operation_id() operation_id = generate_operation_id()
...@@ -215,7 +219,7 @@ class ExtensionService( ...@@ -215,7 +219,7 @@ class ExtensionService(
self.result_log("удаления", operation_id, request, errors_list) 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): async def Uninstall(self, request: extension_service_pb2.UninstallRequest, context):
operation_id = generate_operation_id() operation_id = generate_operation_id()
...@@ -239,7 +243,7 @@ class ExtensionService( ...@@ -239,7 +243,7 @@ class ExtensionService(
self.result_log("проверки", operation_id, request, errors_list) 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): async def Check(self, request: extension_service_pb2.CheckRequest, context):
operation_id = generate_operation_id() operation_id = generate_operation_id()
...@@ -262,7 +266,7 @@ class ExtensionService( ...@@ -262,7 +266,7 @@ class ExtensionService(
return None return None
async def Get(self, request: operation_service_pb2.GetOperationRequest, context): 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: if not operations_meta:
error_description = "Ошибка проверки операции %s в расширении %s - не найдена" % ( error_description = "Ошибка проверки операции %s в расширении %s - не найдена" % (
...@@ -287,7 +291,7 @@ class ExtensionService( ...@@ -287,7 +291,7 @@ class ExtensionService(
return operations_meta.to_operation() return operations_meta.to_operation()
def Cancel(self, request: operation_service_pb2.CancelOperationRequest, context): 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: if not operations_meta:
error_description = "Не удалось удалить операцию %s в расширении %s - не найдена" % ( error_description = "Не удалось удалить операцию %s в расширении %s - не найдена" % (
...@@ -306,8 +310,7 @@ class ExtensionService( ...@@ -306,8 +310,7 @@ class ExtensionService(
try: try:
operations_meta.task.cancel() operations_meta.task.cancel()
operations_meta.mark_cancelled()
operations_meta.response = "Отменено"
except Exception as e: except Exception as e:
error_description = "Во время отмены операции %s расширении %s произошла ошибка %s" % ( error_description = "Во время отмены операции %s расширении %s произошла ошибка %s" % (
request.operation_id, request.operation_id,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment