From bc9af396256d1b3f217a8fe86433cbb294ba3cba Mon Sep 17 00:00:00 2001 From: CamDavidsonPilon Date: Sun, 7 Jul 2024 20:25:46 -0400 Subject: [PATCH] clean up profile code --- CHANGELOG.md | 1 + .../actions/leader/experiment_profile.py | 51 +++++++++++-------- .../tests/test_execute_experiment_profile.py | 3 +- 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6134047d..083c8052 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/pioreactor/actions/leader/experiment_profile.py b/pioreactor/actions/leader/experiment_profile.py index 2ba23898..993cf825 100644 --- a/pioreactor/actions/leader/experiment_profile.py +++ b/pioreactor/actions/leader/experiment_profile.py @@ -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_): @@ -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): @@ -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): @@ -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 _: @@ -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. @@ -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. @@ -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. @@ -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. @@ -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], @@ -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], @@ -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], @@ -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. diff --git a/pioreactor/tests/test_execute_experiment_profile.py b/pioreactor/tests/test_execute_experiment_profile.py index 550e1ab1..1b2eaf1b 100644 --- a/pioreactor/tests/test_execute_experiment_profile.py +++ b/pioreactor/tests/test_execute_experiment_profile.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import annotations +import os from unittest.mock import patch import pytest @@ -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"