Skip to content

Commit 69b3f0f

Browse files
authored
Merge branch 'master' into fix/drop-on-folder
2 parents bbc316f + 493488c commit 69b3f0f

File tree

82 files changed

+894
-343
lines changed

Some content is hidden

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

82 files changed

+894
-343
lines changed

packages/models-library/src/models_library/api_schemas_directorv2/dynamic_services.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,5 @@ class DynamicServiceCreate(ServiceDetails):
7979

8080
class GetProjectInactivityResponse(BaseModel):
8181
is_inactive: bool
82+
83+
model_config = ConfigDict(json_schema_extra={"example": {"is_inactive": "false"}})

packages/models-library/src/models_library/api_schemas_resource_usage_tracker/licensed_items_checkouts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
from models_library.licensed_items import LicensedItemID
55
from models_library.products import ProductName
6-
from models_library.resource_tracker import ServiceRunId
76
from models_library.resource_tracker_licensed_items_checkouts import (
87
LicensedItemCheckoutID,
98
)
9+
from models_library.services_types import ServiceRunID
1010
from models_library.users import UserID
1111
from models_library.wallets import WalletID
1212
from pydantic import BaseModel, ConfigDict, PositiveInt
@@ -18,7 +18,7 @@ class LicensedItemCheckoutGet(BaseModel):
1818
wallet_id: WalletID
1919
user_id: UserID
2020
product_name: ProductName
21-
service_run_id: ServiceRunId
21+
service_run_id: ServiceRunID
2222
started_at: datetime
2323
stopped_at: datetime | None
2424
num_of_seats: int

packages/models-library/src/models_library/api_schemas_resource_usage_tracker/service_runs.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66

77
from ..projects import ProjectID
88
from ..projects_nodes_io import NodeID
9-
from ..resource_tracker import CreditTransactionStatus, ServiceRunId, ServiceRunStatus
9+
from ..resource_tracker import CreditTransactionStatus, ServiceRunStatus
1010
from ..services import ServiceKey, ServiceVersion
11+
from ..services_types import ServiceRunID
1112
from ..users import UserID
1213
from ..wallets import WalletID
1314

1415

1516
class ServiceRunGet(BaseModel):
16-
service_run_id: ServiceRunId
17+
service_run_id: ServiceRunID
1718
wallet_id: WalletID | None
1819
wallet_name: str | None
1920
user_id: UserID

packages/models-library/src/models_library/api_schemas_webserver/resource_usage.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
PricingPlanId,
1212
PricingUnitCostUpdate,
1313
PricingUnitId,
14-
ServiceRunId,
1514
ServiceRunStatus,
1615
SpecificInfo,
1716
UnitExtraInfo,
1817
)
1918
from ..services import ServiceKey, ServiceVersion
19+
from ..services_types import ServiceRunID
2020
from ..users import UserID
2121
from ..wallets import WalletID
2222
from ._base import InputSchema, OutputSchema
@@ -27,7 +27,7 @@
2727
class ServiceRunGet(
2828
BaseModel
2929
): # NOTE: this is already in use so I didnt modidy inheritance from OutputSchema
30-
service_run_id: ServiceRunId
30+
service_run_id: ServiceRunID
3131
wallet_id: WalletID | None
3232
wallet_name: str | None
3333
user_id: UserID

packages/models-library/src/models_library/rabbitmq_messages.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from .projects_state import RunningState
1616
from .services import ServiceKey, ServiceType, ServiceVersion
1717
from .services_resources import ServiceResourcesDict
18+
from .services_types import ServiceRunID
1819
from .users import UserID
1920
from .utils.enums import StrAutoEnum
2021
from .wallets import WalletID
@@ -178,7 +179,7 @@ class RabbitResourceTrackingMessageType(StrAutoEnum):
178179
class RabbitResourceTrackingBaseMessage(RabbitMessageBase):
179180
channel_name: Literal["io.simcore.service.tracking"] = "io.simcore.service.tracking"
180181

181-
service_run_id: str = Field(
182+
service_run_id: ServiceRunID = Field(
182183
..., description="uniquely identitifies the service run"
183184
)
184185
created_at: datetime.datetime = Field(

packages/models-library/src/models_library/resource_tracker.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
_logger = logging.getLogger(__name__)
2222

23-
ServiceRunId: TypeAlias = str
2423
PricingPlanId: TypeAlias = PositiveInt
2524
PricingUnitId: TypeAlias = PositiveInt
2625
PricingUnitCostId: TypeAlias = PositiveInt

packages/models-library/src/models_library/rpc_pagination.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,22 @@
3030
class PageRefsParams(PageRefs[PageQueryParameters]):
3131
@classmethod
3232
def create(cls, total: int, limit: int, offset: int) -> "PageRefsParams":
33-
last_page = ceil(total / limit) - 1
33+
last_page = ceil(total / limit) - 1 if total > 0 else 0
3434
return cls.model_validate(
3535
{
3636
"self": {"offset": offset, "limit": limit},
3737
"first": {"offset": 0, "limit": limit},
3838
"prev": (
3939
{"offset": max(offset - limit, 0), "limit": limit}
40-
if offset > 0
40+
if offset > 0 and total > 0
4141
else None
4242
),
4343
"next": (
4444
{
4545
"offset": min(offset + limit, last_page * limit),
4646
"limit": limit,
4747
}
48-
if offset < (last_page * limit)
48+
if offset < (last_page * limit) and total > 0
4949
else None
5050
),
5151
"last": {"offset": last_page * limit, "limit": limit},

packages/models-library/src/models_library/services.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
from .services_metadata_published import ServiceInputsDict, ServiceMetaDataPublished
88
from .services_types import (
99
DynamicServiceKey,
10-
RunID,
1110
ServiceKey,
1211
ServicePortKey,
12+
ServiceRunID,
1313
ServiceVersion,
1414
)
1515

@@ -21,14 +21,14 @@
2121
"BootOptions",
2222
"DynamicServiceKey",
2323
"LATEST_INTEGRATION_VERSION",
24-
"RunID",
2524
"ServiceInput",
2625
"ServiceInputsDict",
2726
"ServiceKey",
2827
"ServiceKeyVersion",
2928
"ServiceMetaDataPublished",
3029
"ServiceOutput",
3130
"ServicePortKey",
31+
"ServiceRunID",
3232
"ServiceType",
3333
"ServiceVersion",
3434
)

packages/models-library/src/models_library/services_types.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
1-
from typing import Annotated, Any, TypeAlias
1+
from typing import TYPE_CHECKING, Annotated, Any, Self, TypeAlias
22
from uuid import uuid4
33

44
import arrow
5-
from pydantic import GetCoreSchemaHandler, StringConstraints, ValidationInfo
5+
from pydantic import (
6+
GetCoreSchemaHandler,
7+
PositiveInt,
8+
StringConstraints,
9+
ValidationInfo,
10+
)
611
from pydantic_core import CoreSchema, core_schema
712

813
from .basic_regex import PROPERTY_KEY_RE, SIMPLE_VERSION_RE
14+
from .projects_nodes_io import NodeID
915
from .services_regex import (
1016
COMPUTATIONAL_SERVICE_KEY_RE,
1117
DYNAMIC_SERVICE_KEY_RE,
1218
FILENAME_RE,
1319
SERVICE_ENCODED_KEY_RE,
1420
SERVICE_KEY_RE,
1521
)
22+
from .users import UserID
23+
24+
if TYPE_CHECKING:
25+
from .projects import ProjectID
1626

1727
ServicePortKey: TypeAlias = Annotated[str, StringConstraints(pattern=PROPERTY_KEY_RE)]
1828

@@ -35,7 +45,7 @@
3545
ServiceVersion: TypeAlias = Annotated[str, StringConstraints(pattern=SIMPLE_VERSION_RE)]
3646

3747

38-
class RunID(str):
48+
class ServiceRunID(str):
3949
"""
4050
Used to assign a unique identifier to the run of a service.
4151
@@ -44,12 +54,15 @@ class RunID(str):
4454
and old volumes for different runs.
4555
Avoids overwriting data that left dropped on the node (due to an error)
4656
and gives the osparc-agent an opportunity to back it up.
57+
The resource-usage-tracker tracker uses these RunIDs to keep track of
58+
resource usage from computational and dynamic services.
4759
"""
4860

4961
__slots__ = ()
5062

5163
@classmethod
52-
def create(cls) -> "RunID":
64+
def get_resource_tracking_run_id_for_dynamic(cls) -> Self:
65+
"""used for dynamic services"""
5366
# NOTE: there was a legacy version of this RunID
5467
# legacy version:
5568
# '0ac3ed64-665b-42d2-95f7-e59e0db34242'
@@ -59,6 +72,17 @@ def create(cls) -> "RunID":
5972
run_id_format = f"{utc_int_timestamp}_{uuid4()}"
6073
return cls(run_id_format)
6174

75+
@classmethod
76+
def get_resource_tracking_run_id_for_computational(
77+
cls,
78+
user_id: UserID,
79+
project_id: "ProjectID",
80+
node_id: NodeID,
81+
iteration: PositiveInt,
82+
) -> Self:
83+
"""used by computational services"""
84+
return cls(f"comp_{user_id}_{project_id}_{node_id}_{iteration}")
85+
6286
@classmethod
6387
def __get_pydantic_core_schema__(
6488
cls,
@@ -68,7 +92,7 @@ def __get_pydantic_core_schema__(
6892
return core_schema.no_info_after_validator_function(cls, handler(str))
6993

7094
@classmethod
71-
def validate(cls, v: "RunID | str", _: ValidationInfo) -> "RunID":
95+
def validate(cls, v: "ServiceRunID | str", _: ValidationInfo) -> "ServiceRunID":
7296
if isinstance(v, cls):
7397
return v
7498
if isinstance(v, str):

packages/models-library/tests/test_rest_pagination.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44
from models_library.rest_pagination import Page, PageMetaInfoLimitOffset
5-
from pydantic.main import BaseModel
5+
from pydantic import BaseModel, ValidationError
66
from pytest_simcore.examples.models_library import PAGE_EXAMPLES
77

88

@@ -26,7 +26,7 @@ def test_page_response_limit_offset_models(cls_model: BaseModel, examples: list[
2626

2727

2828
def test_invalid_offset():
29-
with pytest.raises(ValueError):
29+
with pytest.raises(ValidationError):
3030
PageMetaInfoLimitOffset(limit=6, total=5, offset=5, count=2)
3131

3232

@@ -39,14 +39,14 @@ def test_invalid_offset():
3939
],
4040
)
4141
def test_invalid_count(count: int, offset: int):
42-
with pytest.raises(ValueError):
42+
with pytest.raises(ValidationError):
4343
PageMetaInfoLimitOffset(limit=6, total=5, offset=offset, count=count)
4444

4545

4646
def test_data_size_does_not_fit_count():
4747
example = deepcopy(PAGE_EXAMPLES[0])
4848
example["_meta"]["count"] = len(example["data"]) - 1
49-
with pytest.raises(ValueError):
49+
with pytest.raises(ValidationError):
5050
Page[str](**example)
5151

5252

0 commit comments

Comments
 (0)