Skip to content

Commit bc7ac1a

Browse files
authored
chore: add private _run_task_without_session_env function to the Session class (#281)
Signed-off-by: Godot Bian <[email protected]>
1 parent 9695b97 commit bc7ac1a

File tree

2 files changed

+462
-0
lines changed

2 files changed

+462
-0
lines changed

src/openjd/sessions/_session.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,63 @@ def run_task(
843843
# than after -- run() itself may end up setting the action state to FAILED.
844844
self._runner.run()
845845

846+
def _run_task_without_session_env(
847+
self,
848+
*,
849+
step_script: StepScriptModel,
850+
task_parameter_values: TaskParameterSet,
851+
os_env_vars: Optional[dict[str, str]] = None,
852+
log_task_banner: bool = True,
853+
) -> None:
854+
"""Private API to run a task within the session.
855+
This method directly use os_env_vars passed in without applying additional session env setup.
856+
"""
857+
if self.state != SessionState.READY:
858+
raise RuntimeError("Session must be in the READY state to run a task.")
859+
860+
if log_task_banner:
861+
log_section_banner(self._logger, "Running Task")
862+
863+
if task_parameter_values:
864+
self._logger.info(
865+
"Parameter values:",
866+
extra=LogExtraInfo(openjd_log_content=LogContent.PARAMETER_INFO),
867+
)
868+
for name, value in task_parameter_values.items():
869+
self._logger.info(
870+
f"{name}({str(value.type.value)}) = {value.value}",
871+
extra=LogExtraInfo(openjd_log_content=LogContent.PARAMETER_INFO),
872+
)
873+
874+
self._reset_action_state()
875+
symtab = self._symbol_table(step_script.revision, task_parameter_values)
876+
877+
# Evaluate environment variables
878+
action_env_vars = dict[str, Optional[str]](self._process_env) # Make a copy
879+
if os_env_vars:
880+
action_env_vars.update(**os_env_vars)
881+
882+
self._materialize_path_mapping(step_script.revision, action_env_vars, symtab)
883+
self._runner = StepScriptRunner(
884+
logger=self._logger,
885+
user=self._user,
886+
os_env_vars=action_env_vars,
887+
session_working_directory=self.working_directory,
888+
startup_directory=self.working_directory,
889+
callback=self._action_callback,
890+
script=step_script,
891+
symtab=symtab,
892+
session_files_directory=self.files_directory,
893+
)
894+
# Sets the subprocess running.
895+
# Returns immediately after it has started, or is running
896+
self._action_state = ActionState.RUNNING
897+
self._state = SessionState.RUNNING
898+
# Note: This may fail immediately (e.g. if we cannot write embedded files to disk),
899+
# so it's important to set the action_state to RUNNING before calling run(), rather
900+
# than after -- run() itself may end up setting the action state to FAILED.
901+
self._runner.run()
902+
846903
# =========================
847904
# Helpers
848905

0 commit comments

Comments
 (0)