Skip to content

Commit

Permalink
feat: add ability to not log banner when running a task (#204)
Browse files Browse the repository at this point in the history
Signed-off-by: Godot Bian <[email protected]>
Co-authored-by: Godot Bian <[email protected]>
  • Loading branch information
godobyte and godobyte authored Jan 21, 2025
1 parent b9be7a4 commit e8acc8a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/openjd/sessions/_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,7 @@ def run_task(
step_script: StepScriptModel,
task_parameter_values: TaskParameterSet,
os_env_vars: Optional[dict[str, str]] = None,
log_task_banner: bool = True,
) -> None:
"""Run a Task within the Session.
This method is non-blocking; it will exit when the subprocess is either confirmed to have
Expand All @@ -776,11 +777,15 @@ def run_task(
by values defined in Environments.
Key: Environment variable name
Value: Value for the environment variable.
log_task_banner (bool): Whether to log a banner before running the Task.
Default: True
"""
if self.state != SessionState.READY:
raise RuntimeError("Session must be in the READY state to run a task.")

log_section_banner(self._logger, "Running Task")
if log_task_banner:
log_section_banner(self._logger, "Running Task")

if task_parameter_values:
self._logger.info(
"Parameter values:",
Expand Down
20 changes: 20 additions & 0 deletions test/openjd/sessions/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,26 @@ def test_run_task(
assert session.action_status == ActionStatus(state=ActionState.SUCCESS, exit_code=0)
assert "Jvalue Jvalue" in caplog.messages
assert "Pvalue Pvalue" in caplog.messages
assert "--------- Running Task" in caplog.messages

def test_run_task_no_log_banners(
self, caplog: pytest.LogCaptureFixture, fix_basic_task_script: StepScript_2023_09
) -> None:
# GIVEN
# This ensures that the log_task_banner argument is correctly controlling the task banner logging.
session_id = uuid.uuid4().hex
job_params = {"J": ParameterValue(type=ParameterValueType.STRING, value="Jvalue")}
task_params = {"P": ParameterValue(type=ParameterValueType.STRING, value="Pvalue")}
with Session(session_id=session_id, job_parameter_values=job_params) as session:
# WHEN
session.run_task(
step_script=fix_basic_task_script,
task_parameter_values=task_params,
log_task_banner=False,
)

# THEN
assert "--------- Running Task" not in caplog.messages

def test_run_task_with_env_vars(self, caplog: pytest.LogCaptureFixture) -> None:
# GIVEN
Expand Down

0 comments on commit e8acc8a

Please sign in to comment.