Skip to content

Commit 82861ce

Browse files
author
Andrei Neagu
committed
fixed issue with method registration
1 parent 2380c61 commit 82861ce

File tree

7 files changed

+24
-35
lines changed

7 files changed

+24
-35
lines changed

packages/service-library/src/servicelib/long_running_tasks/_rabbit/lrt_server.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import logging
22
from typing import Any
33

4-
from common_library.error_codes import create_error_code
5-
6-
from ...logging_errors import create_troubleshootting_log_kwargs
74
from ...rabbitmq import RPCRouter
85
from .._serialization import object_to_string
96
from ..base_long_running_manager import BaseLongRunningManager
@@ -74,15 +71,7 @@ async def _get_transferarble_task_result(
7471
return task_result
7572
except (TaskNotFoundError, TaskNotCompletedError):
7673
raise
77-
except Exception as exc:
78-
_logger.exception(
79-
**create_troubleshootting_log_kwargs(
80-
user_error_msg=f"{task_id=} raised an exception while getting its result",
81-
error=exc,
82-
error_code=create_error_code(exc),
83-
error_context={"task_context": task_context, "task_id": task_id},
84-
),
85-
)
74+
except Exception:
8675
# the task shall be removed in this case
8776
await long_running_manager.tasks_manager.remove_task(
8877
task_id, with_task_context=task_context, reraise_errors=False

packages/service-library/src/servicelib/long_running_tasks/task.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,10 @@ def __name__(self) -> str: ...
6060
class TaskRegistry:
6161
REGISTERED_TASKS: ClassVar[dict[RegisteredTaskName, TaskProtocol]] = {}
6262

63-
# TODO: maybe only use one method to register
6463
@classmethod
65-
def register(cls, task: TaskProtocol) -> None:
66-
cls.REGISTERED_TASKS[task.__name__] = task
67-
68-
@classmethod
69-
def register_partial(cls, task: TaskProtocol, **partial_kwargs) -> None:
64+
def register(cls, task: TaskProtocol, **partial_kwargs) -> None:
7065
partail_task = functools.partial(task, **partial_kwargs)
71-
# allows to call via the partial of via the orignal method
66+
# allows to call the partial via it's original name
7267
partail_task.__name__ = task.__name__ # type: ignore[attr-defined]
7368
cls.REGISTERED_TASKS[task.__name__] = partail_task # type: ignore[assignment]
7469

services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/modules/long_running_tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,6 @@ async def on_startup() -> None:
672672
}
673673

674674
for handler, context in task_context.items():
675-
TaskRegistry.register_partial(handler, **context)
675+
TaskRegistry.register(handler, **context)
676676

677677
app.add_event_handler("startup", on_startup)

services/web/server/src/simcore_service_webserver/long_running_tasks.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,21 @@
1010
)
1111
from servicelib.aiohttp.long_running_tasks.server import setup
1212
from servicelib.aiohttp.typing_extension import Handler
13-
from servicelib.long_running_tasks.models import RabbitNamespace
14-
from servicelib.long_running_tasks.task import RedisNamespace
1513

1614
from . import rabbitmq_settings, redis
1715
from ._meta import API_VTAG
1816
from .login.decorators import login_required
1917
from .models import AuthenticatedRequestContext
18+
from .projects.plugin import register_projects_long_running_tasks
2019

2120
_logger = logging.getLogger(__name__)
2221

23-
_LRT_REDIS_NAMESPACE: Final[RedisNamespace] = "webserver-legacy"
24-
_LRT_RABBIT_NAMESPACE: Final[RabbitNamespace] = "webserver-legacy"
22+
23+
_LRT_NAMESPACE_PREFIX: Final[str] = "webserver-legacy"
24+
25+
26+
def _get_namespace(suffix: str) -> str:
27+
return f"{_LRT_NAMESPACE_PREFIX}-{suffix}"
2528

2629

2730
def webserver_request_context_decorator(handler: Handler):
@@ -39,13 +42,17 @@ async def _test_task_context_decorator(
3942

4043
@ensure_single_setup(__name__, logger=_logger)
4144
def setup_long_running_tasks(app: web.Application) -> None:
45+
# register all long-running tasks from different modules
46+
register_projects_long_running_tasks(app)
47+
48+
namespace_suffix = "TODO" # TODO recover from settings
4249

4350
setup(
4451
app,
4552
redis_settings=redis.get_plugin_settings(app),
4653
rabbit_settings=rabbitmq_settings.get_plugin_settings(app),
47-
redis_namespace=_LRT_REDIS_NAMESPACE,
48-
rabbit_namespace=_LRT_RABBIT_NAMESPACE,
54+
redis_namespace=_get_namespace(namespace_suffix),
55+
rabbit_namespace=_get_namespace(namespace_suffix),
4956
router_prefix=f"/{API_VTAG}/tasks-legacy",
5057
handler_check_decorator=login_required,
5158
task_request_context_decorator=webserver_request_context_decorator,

services/web/server/src/simcore_service_webserver/projects/_controller/nodes_rest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ async def _stop_dynamic_service_task(
323323

324324

325325
def register_stop_dynamic_service_task(app: web.Application) -> None:
326-
TaskRegistry.register_partial(_stop_dynamic_service_task, app=app)
326+
TaskRegistry.register(_stop_dynamic_service_task, app=app)
327327

328328

329329
@routes.post(

services/web/server/src/simcore_service_webserver/projects/_crud_api_create.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -522,8 +522,4 @@ async def create_project( # pylint: disable=too-many-arguments,too-many-branche
522522

523523

524524
def register_create_project_task(app: web.Application) -> None:
525-
TaskRegistry.register_partial(create_project, app=app)
526-
_logger.debug(
527-
"I've manged to register the create_project task %s",
528-
TaskRegistry.REGISTERED_TASKS,
529-
)
525+
TaskRegistry.register(create_project, app=app)

services/web/server/src/simcore_service_webserver/projects/plugin.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
logger = logging.getLogger(__name__)
3838

3939

40+
def register_projects_long_running_tasks(app: web.Application) -> None:
41+
register_create_project_task(app)
42+
register_stop_dynamic_service_task(app)
43+
44+
4045
@app_module_setup(
4146
"simcore_service_webserver.projects",
4247
ModuleCategory.ADDON,
@@ -77,7 +82,4 @@ def setup_projects(app: web.Application) -> bool:
7782
app.router.add_routes(workspaces_rest.routes)
7883
app.router.add_routes(trash_rest.routes)
7984

80-
register_create_project_task(app)
81-
register_stop_dynamic_service_task(app)
82-
8385
return True

0 commit comments

Comments
 (0)