Skip to content

Commit

Permalink
clean up profile code
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Jul 8, 2024
1 parent 0a94606 commit bc9af39
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- `unit()` can be used in mqtt fetch expressions. Example: `unit():stirring:target_rpm` is identical to `::stirring:target_rpm`. The latter can be seen as a shortened version of the former.
- Breaking change: `log` in experiment profiles now uses expressions instead of python formatting. For example: `The unit {unit} is running {job} in experiment {experiment}` should be replaced by expressions in the string: `The unit ${{unit()}} is running ${{job_name()}} in the experiment ${{experiment}}`.
- Updated Raspberry Pi OS image to 2024-07-04.
- experiment profiles can have a `description` in the `job` field (i.e. beside `actions`.)


### 24.7.5 & 24.7.6 & 24.7.7
Expand Down
51 changes: 30 additions & 21 deletions pioreactor/actions/leader/experiment_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,13 @@ def wrapped_execute_action(
experiment,
client,
job_name,
options,
args,
dry_run,
if_,
env,
logger,
elapsed_seconds_func,
options,
args,
)

case struct.Pause(_, if_):
Expand All @@ -216,12 +216,21 @@ def wrapped_execute_action(

case struct.Update(_, if_, options):
return update_job(
unit, experiment, client, job_name, options, dry_run, if_, env, logger, elapsed_seconds_func
unit, experiment, client, job_name, dry_run, if_, env, logger, elapsed_seconds_func, options
)

case struct.Log(_, options, if_):
return log(
unit, experiment, client, job_name, options, dry_run, if_, env, logger, elapsed_seconds_func
unit,
experiment,
client,
job_name,
dry_run,
if_,
env,
logger,
elapsed_seconds_func,
options,
)

case struct.Repeat(_, if_, repeat_every_hours, while_, max_hours, actions):
Expand All @@ -234,13 +243,13 @@ def wrapped_execute_action(
if_,
env,
logger,
elapsed_seconds_func,
action,
while_,
repeat_every_hours,
max_hours,
actions,
schedule,
elapsed_seconds_func,
)

case struct.When(_, if_, condition, actions):
Expand All @@ -252,12 +261,12 @@ def wrapped_execute_action(
dry_run,
if_,
env,
condition,
logger,
elapsed_seconds_func,
condition,
action,
actions,
schedule,
elapsed_seconds_func,
)

case _:
Expand Down Expand Up @@ -301,12 +310,12 @@ def when(
dry_run: bool,
if_: Optional[bool_expression],
env: dict,
condition: bool_expression,
logger: CustomLogger,
elapsed_seconds_func: Callable[[], float],
condition: bool_expression,
when_action: struct.When,
actions: list[struct.Action],
schedule: scheduler,
elapsed_seconds_func: Callable[[], float],
) -> Callable[..., None]:
def _callable() -> None:
# first check if the Pioreactor is still part of the experiment.
Expand Down Expand Up @@ -371,13 +380,13 @@ def repeat(
if_: Optional[bool_expression],
env: dict,
logger: CustomLogger,
elapsed_seconds_func: Callable[[], float],
repeat_action: struct.Repeat,
while_: Optional[bool_expression],
repeat_every_hours: float,
max_hours: Optional[float],
actions: list[struct.BasicAction],
schedule: scheduler,
elapsed_seconds_func: Callable[[], float],
) -> Callable[..., None]:
def _callable() -> None:
# first check if the Pioreactor is still part of the experiment.
Expand Down Expand Up @@ -451,12 +460,12 @@ def log(
experiment: str,
client: Client,
job_name: str,
options: struct._LogOptions,
dry_run: bool,
if_: Optional[str | bool],
if_: Optional[bool_expression],
env: dict,
logger: CustomLogger,
elapsed_seconds_func,
elapsed_seconds_func: Callable[[], float],
options: struct._LogOptions,
) -> Callable[..., None]:
def _callable() -> None:
# first check if the Pioreactor is still part of the experiment.
Expand All @@ -479,13 +488,13 @@ def start_job(
experiment: str,
client: Client,
job_name: str,
options: dict,
args: list,
dry_run: bool,
if_: Optional[str | bool],
if_: Optional[bool_expression],
env: dict,
logger: CustomLogger,
elapsed_seconds_func: Callable[[], float],
options: dict,
args: list,
) -> Callable[..., None]:
def _callable() -> None:
# first check if the Pioreactor is still part of the experiment.
Expand Down Expand Up @@ -518,7 +527,7 @@ def pause_job(
client: Client,
job_name: str,
dry_run: bool,
if_: Optional[str | bool],
if_: Optional[bool_expression],
env: dict,
logger: CustomLogger,
elapsed_seconds_func: Callable[[], float],
Expand Down Expand Up @@ -547,7 +556,7 @@ def resume_job(
client: Client,
job_name: str,
dry_run: bool,
if_: Optional[str | bool],
if_: Optional[bool_expression],
env: dict,
logger: CustomLogger,
elapsed_seconds_func: Callable[[], float],
Expand Down Expand Up @@ -576,7 +585,7 @@ def stop_job(
client: Client,
job_name: str,
dry_run: bool,
if_: Optional[str | bool],
if_: Optional[bool_expression],
env: dict,
logger: CustomLogger,
elapsed_seconds_func: Callable[[], float],
Expand Down Expand Up @@ -604,12 +613,12 @@ def update_job(
experiment: str,
client: Client,
job_name: str,
options: dict,
dry_run: bool,
if_: Optional[str | bool],
if_: Optional[bool_expression],
env: dict,
logger: CustomLogger,
elapsed_seconds_func: Callable[[], float],
options: dict,
) -> Callable[..., None]:
def _callable() -> None:
# first check if the Pioreactor is still part of the experiment.
Expand Down
3 changes: 2 additions & 1 deletion pioreactor/tests/test_execute_experiment_profile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import annotations

import os
from unittest.mock import patch

import pytest
Expand Down Expand Up @@ -125,7 +126,7 @@ def collection_actions(msg):
]


@pytest.mark.skip(reason="flakey test in CI???")
@pytest.mark.skipif(os.getenv("GITHUB_ACTIONS") == "true", reason="flakey test in CI???")
@patch("pioreactor.actions.leader.experiment_profile._load_experiment_profile")
def test_execute_experiment_log_actions(mock__load_experiment_profile, active_workers_in_cluster) -> None:
experiment = "_testing_experiment"
Expand Down

0 comments on commit bc9af39

Please sign in to comment.