Skip to content

Commit b4a3ca1

Browse files
Merge branch 'is8102/add-search-api-in-storage' of github.com:giancarloromeo/osparc-simcore into is8102/add-search-api-in-storage
2 parents 39d3300 + 4eeda4f commit b4a3ca1

File tree

54 files changed

+3363
-793
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+3363
-793
lines changed

packages/celery-library/src/celery_library/errors.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,11 @@ def decode_celery_transferrable_error(error: TransferrableCeleryError) -> Except
2626
return result
2727

2828

29+
class TaskSubmissionError(OsparcErrorMixin, Exception):
30+
msg_template = (
31+
"Unable to submit task {task_name} with id '{task_id}' and params {task_params}"
32+
)
33+
34+
2935
class TaskNotFoundError(OsparcErrorMixin, Exception):
3036
msg_template = "Task with id '{task_id}' was not found"

packages/celery-library/src/celery_library/task_manager.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from uuid import uuid4
55

66
from celery import Celery # type: ignore[import-untyped]
7+
from celery.exceptions import CeleryError # type: ignore[import-untyped]
78
from common_library.async_tools import make_async
89
from models_library.progress_bar import ProgressReport
910
from servicelib.celery.models import (
@@ -21,7 +22,7 @@
2122
from servicelib.logging_utils import log_context
2223
from settings_library.celery import CelerySettings
2324

24-
from .errors import TaskNotFoundError
25+
from .errors import TaskNotFoundError, TaskSubmissionError
2526

2627
_logger = logging.getLogger(__name__)
2728

@@ -50,21 +51,38 @@ async def submit_task(
5051
):
5152
task_uuid = uuid4()
5253
task_id = task_filter.create_task_id(task_uuid=task_uuid)
53-
self._celery_app.send_task(
54-
task_metadata.name,
55-
task_id=task_id,
56-
kwargs={"task_id": task_id} | task_params,
57-
queue=task_metadata.queue.value,
58-
)
5954

6055
expiry = (
6156
self._celery_settings.CELERY_EPHEMERAL_RESULT_EXPIRES
6257
if task_metadata.ephemeral
6358
else self._celery_settings.CELERY_RESULT_EXPIRES
6459
)
65-
await self._task_info_store.create_task(
66-
task_id, task_metadata, expiry=expiry
67-
)
60+
61+
try:
62+
await self._task_info_store.create_task(
63+
task_id, task_metadata, expiry=expiry
64+
)
65+
self._celery_app.send_task(
66+
task_metadata.name,
67+
task_id=task_id,
68+
kwargs={"task_id": task_id} | task_params,
69+
queue=task_metadata.queue.value,
70+
)
71+
except CeleryError as exc:
72+
try:
73+
await self._task_info_store.remove_task(task_id)
74+
except CeleryError:
75+
_logger.warning(
76+
"Unable to cleanup task '%s' during error handling",
77+
task_id,
78+
exc_info=True,
79+
)
80+
raise TaskSubmissionError(
81+
task_name=task_metadata.name,
82+
task_id=task_id,
83+
task_params=task_params,
84+
) from exc
85+
6886
return task_uuid
6987

7088
async def cancel_task(self, task_filter: TaskFilter, task_uuid: TaskUUID) -> None:

packages/service-library/setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ markers =
2121
testit: "marks test to run during development"
2222
performance_test: "performance test"
2323
no_cleanup_check_rabbitmq_server_has_no_errors: "no check in rabbitmq logs"
24+
heavy_load: "marks test as heavy load"
2425

2526
[mypy]
2627
plugins =

packages/service-library/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def read_reqs(reqs_path: Path) -> set[str]:
3838
"python_requires": "~=3.11",
3939
"install_requires": tuple(PROD_REQUIREMENTS),
4040
"packages": find_packages(where="src"),
41-
"package_data": {"": ["py.typed"]},
41+
"package_data": {"": ["py.typed", "redis/lua/*.lua"]},
4242
"package_dir": {"": "src"},
4343
"test_suite": "tests",
4444
"tests_require": tuple(TEST_REQUIREMENTS),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from common_library.async_tools import cancel_wait_task
1212
from models_library.api_schemas_long_running_tasks.base import TaskProgress
1313
from pydantic import NonNegativeFloat, PositiveFloat
14-
from servicelib.utils import limited_gather
1514
from settings_library.redis import RedisDatabase, RedisSettings
1615
from tenacity import (
1716
AsyncRetrying,
@@ -24,6 +23,7 @@
2423
from ..logging_errors import create_troubleshootting_log_kwargs
2524
from ..logging_utils import log_catch, log_context
2625
from ..redis import RedisClientSDK, exclusive
26+
from ..utils import limited_gather
2727
from ._redis_store import RedisStore
2828
from ._serialization import dumps
2929
from .errors import (

packages/service-library/src/servicelib/redis/__init__.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
CouldNotConnectToRedisError,
77
LockLostError,
88
ProjectLockError,
9+
SemaphoreAcquisitionError,
10+
SemaphoreNotAcquiredError,
911
)
1012
from ._models import RedisManagerDBConfig
1113
from ._project_document_version import (
@@ -18,24 +20,26 @@
1820
is_project_locked,
1921
with_project_locked,
2022
)
23+
from ._semaphore_decorator import with_limited_concurrency
2124
from ._utils import handle_redis_returns_union_types
2225

2326
__all__: tuple[str, ...] = (
27+
"PROJECT_DB_UPDATE_REDIS_LOCK_KEY",
28+
"PROJECT_DOCUMENT_VERSION_KEY",
2429
"CouldNotAcquireLockError",
2530
"CouldNotConnectToRedisError",
26-
"exclusive",
27-
"increment_and_return_project_document_version",
28-
"get_project_locked_state",
29-
"handle_redis_returns_union_types",
30-
"is_project_locked",
3131
"LockLostError",
32-
"PROJECT_DB_UPDATE_REDIS_LOCK_KEY",
33-
"PROJECT_DOCUMENT_VERSION_KEY",
3432
"ProjectLockError",
3533
"RedisClientSDK",
3634
"RedisClientsManager",
3735
"RedisManagerDBConfig",
36+
"SemaphoreAcquisitionError",
37+
"SemaphoreNotAcquiredError",
38+
"exclusive",
39+
"get_project_locked_state",
40+
"handle_redis_returns_union_types",
41+
"increment_and_return_project_document_version",
42+
"is_project_locked",
43+
"with_limited_concurrency",
3844
"with_project_locked",
3945
)
40-
41-
# nopycln: file

packages/service-library/src/servicelib/redis/_constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
DEFAULT_LOCK_TTL: Final[datetime.timedelta] = datetime.timedelta(seconds=10)
77
DEFAULT_SOCKET_TIMEOUT: Final[datetime.timedelta] = datetime.timedelta(seconds=30)
88

9+
DEFAULT_SEMAPHORE_TTL: Final[datetime.timedelta] = datetime.timedelta(seconds=10)
10+
SEMAPHORE_KEY_PREFIX: Final[str] = "semaphores:"
11+
SEMAPHORE_HOLDER_KEY_PREFIX: Final[str] = "semaphores:holders:"
912

1013
DEFAULT_DECODE_RESPONSES: Final[bool] = True
1114
DEFAULT_HEALTH_CHECK_INTERVAL: Final[datetime.timedelta] = datetime.timedelta(seconds=5)

packages/service-library/src/servicelib/redis/_errors.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
from common_library.errors_classes import OsparcErrorMixin
55

66

7-
class BaseRedisError(OsparcErrorMixin, RuntimeError):
8-
...
7+
class BaseRedisError(OsparcErrorMixin, RuntimeError): ...
98

109

1110
class CouldNotAcquireLockError(BaseRedisError):
@@ -25,3 +24,15 @@ class LockLostError(BaseRedisError):
2524

2625

2726
ProjectLockError: TypeAlias = redis.exceptions.LockError # NOTE: backwards compatible
27+
28+
29+
class SemaphoreAcquisitionError(BaseRedisError):
30+
msg_template: str = "Could not acquire semaphore '{name}' (capacity: {capacity})"
31+
32+
33+
class SemaphoreNotAcquiredError(BaseRedisError):
34+
msg_template: str = "Semaphore '{name}' was not acquired by this instance"
35+
36+
37+
class SemaphoreLostError(BaseRedisError):
38+
msg_template: str = "Semaphore '{name}' was lost by this instance `{instance_id}`"

0 commit comments

Comments
 (0)