Skip to content

Commit 24ff119

Browse files
author
Andrei Neagu
committed
run_id can now be requested as an env var on request by a service
1 parent a35576c commit 24ff119

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

services/director-v2/src/simcore_service_director_v2/modules/dynamic_sidecar/docker_compose_specs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
ResourceValue,
2121
ServiceResourcesDict,
2222
)
23+
from models_library.services_types import RunID
2324
from models_library.users import UserID
2425
from models_library.utils.docker_compose import replace_env_vars_in_compose_spec
2526
from pydantic import ByteSize
@@ -278,6 +279,7 @@ async def assemble_spec( # pylint: disable=too-many-arguments # noqa: PLR0913
278279
node_id: NodeID,
279280
simcore_user_agent: str,
280281
swarm_stack_name: str,
282+
run_id: RunID,
281283
) -> str:
282284
"""
283285
returns a docker-compose spec used by
@@ -350,6 +352,7 @@ async def assemble_spec( # pylint: disable=too-many-arguments # noqa: PLR0913
350352
product_name=product_name,
351353
project_id=project_id,
352354
node_id=node_id,
355+
run_id=run_id,
353356
)
354357

355358
add_egress_configuration(
@@ -388,6 +391,7 @@ async def assemble_spec( # pylint: disable=too-many-arguments # noqa: PLR0913
388391
product_name=product_name,
389392
project_id=project_id,
390393
node_id=node_id,
394+
run_id=run_id,
391395
)
392396

393397
stringified_service_spec: str = replace_env_vars_in_compose_spec(

services/director-v2/src/simcore_service_director_v2/modules/dynamic_sidecar/scheduler/_core/_events_user_services.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ async def submit_compose_sepc(app: FastAPI, scheduler_data: SchedulerData) -> No
103103
node_id=scheduler_data.node_uuid,
104104
simcore_user_agent=scheduler_data.request_simcore_user_agent,
105105
swarm_stack_name=dynamic_services_scheduler_settings.SWARM_STACK_NAME,
106+
run_id=scheduler_data.run_id,
106107
)
107108

108109
_logger.debug(

services/director-v2/src/simcore_service_director_v2/modules/osparc_variables/substitutions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from models_library.projects_nodes_io import NodeID
1919
from models_library.service_settings_labels import ComposeSpecLabelDict
2020
from models_library.services import ServiceKey, ServiceVersion
21+
from models_library.services_types import RunID
2122
from models_library.users import UserID
2223
from models_library.utils.specs_substitution import SpecsSubstitutionsResolver
2324
from pydantic import BaseModel
@@ -120,6 +121,7 @@ def create(cls, app: FastAPI):
120121
("OSPARC_VARIABLE_NODE_ID", "node_id"),
121122
("OSPARC_VARIABLE_PRODUCT_NAME", "product_name"),
122123
("OSPARC_VARIABLE_STUDY_UUID", "project_id"),
124+
("OSPARC_VARIABLE_RUN_ID", "run_id"),
123125
("OSPARC_VARIABLE_USER_ID", "user_id"),
124126
("OSPARC_VARIABLE_API_HOST", "api_server_base_url"),
125127
]:
@@ -181,6 +183,7 @@ async def resolve_and_substitute_session_variables_in_model(
181183
product_name: str,
182184
project_id: ProjectID,
183185
node_id: NodeID,
186+
run_id: RunID,
184187
) -> TBaseModel:
185188
result: TBaseModel = model
186189
try:
@@ -200,6 +203,7 @@ async def resolve_and_substitute_session_variables_in_model(
200203
product_name=product_name,
201204
project_id=project_id,
202205
node_id=node_id,
206+
run_id=run_id,
203207
api_server_base_url=app.state.settings.DIRECTOR_V2_PUBLIC_API_BASE_URL,
204208
),
205209
)
@@ -221,6 +225,7 @@ async def resolve_and_substitute_session_variables_in_specs(
221225
product_name: str,
222226
project_id: ProjectID,
223227
node_id: NodeID,
228+
run_id: RunID,
224229
) -> dict[str, Any]:
225230
table = OsparcSessionVariablesTable.get_from_app_state(app)
226231
resolver = SpecsSubstitutionsResolver(specs, upgrade=False)
@@ -241,6 +246,7 @@ async def resolve_and_substitute_session_variables_in_specs(
241246
product_name=product_name,
242247
project_id=project_id,
243248
node_id=node_id,
249+
run_id=run_id,
244250
api_server_base_url=app.state.settings.DIRECTOR_V2_PUBLIC_API_BASE_URL,
245251
),
246252
)

services/director-v2/src/simcore_service_director_v2/utils/osparc_variables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def _get_or_raise(context: ContextDict) -> Any:
2525
try:
2626
return context[parameter_name]
2727
except KeyError as err:
28-
msg = "Parameter {keyname} missing from substitution context"
28+
msg = f"{parameter_name=} missing from substitution context"
2929
raise CaptureError(msg) from err
3030

3131
# For context["foo"] -> return operator.methodcaller("__getitem__", keyname)

services/director-v2/tests/unit/test_modules_osparc_variables.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@
4848
def session_context(faker: Faker) -> ContextDict:
4949
return ContextDict(
5050
app=FastAPI(),
51-
service_key=TypeAdapter(ServiceKey).validate_python("simcore/services/dynamic/foo"),
51+
service_key=TypeAdapter(ServiceKey).validate_python(
52+
"simcore/services/dynamic/foo"
53+
),
5254
service_version=TypeAdapter(ServiceVersion).validate_python("1.2.3"),
5355
compose_spec=generate_fake_docker_compose(faker),
5456
product_name=faker.word(),
@@ -101,7 +103,8 @@ async def request_user_email(app: FastAPI, user_id: UserID) -> SubstitutionValue
101103

102104
# All values extracted from the context MUST be SubstitutionValue
103105
assert {
104-
key: TypeAdapter(SubstitutionValue).validate_python(value) for key, value in environs.items()
106+
key: TypeAdapter(SubstitutionValue).validate_python(value)
107+
for key, value in environs.items()
105108
}
106109

107110
for osparc_variable_name, context_name in [
@@ -170,6 +173,7 @@ async def test_resolve_and_substitute_session_variables_in_specs(
170173
"user_role": "${OSPARC_VARIABLE_USER_ROLE}",
171174
"api_key": "${OSPARC_VARIABLE_API_KEY}",
172175
"api_secret": "${OSPARC_VARIABLE_API_SECRET}",
176+
"run_id": "${OSPARC_VARIABLE_RUN_ID}",
173177
}
174178
print("SPECS\n", specs)
175179

@@ -180,6 +184,7 @@ async def test_resolve_and_substitute_session_variables_in_specs(
180184
product_name="a_product",
181185
project_id=faker.uuid4(cast_to=None),
182186
node_id=faker.uuid4(cast_to=None),
187+
run_id="some_run_id",
183188
)
184189
print("REPLACED SPECS\n", replaced_specs)
185190

0 commit comments

Comments
 (0)