Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ability to not log banner when running a task #204

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading