Skip to content

Commit

Permalink
fix: run command exits when an action reaches timeout (#97)
Browse files Browse the repository at this point in the history
Problem:
 When using the run subcommand to run an action that reaches its timeout,
the action is properly ended but the CLI itself does not exit. It's waiting
in _run_local_session() for the session.ended event to be set, but it's not
being set.

Solution:
 The LocalSession's _action_callback method was not handling the case where the
returned ActionState was TIMEOUT. It now handles it.

Signed-off-by: Daniel Neilson <[email protected]>
  • Loading branch information
ddneilson authored Jul 10, 2024
1 parent f6a54b2 commit d031a91
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/openjd/cli/_run/_local_session/_session_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def _action_callback(self, session_id: str, new_status: ActionStatus) -> None:
if isinstance(self._current_action, RunTaskAction):
self.tasks_run += 1
self._action_ended.set()
if new_status.state in (ActionState.FAILED, ActionState.CANCELED):
if new_status.state in (ActionState.FAILED, ActionState.CANCELED, ActionState.TIMEOUT):
self.failed = True
self._action_ended.set()

Expand Down
33 changes: 33 additions & 0 deletions test/openjd/cli/test_run_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,39 @@
True,
id="EnvExitFails_2",
),
pytest.param(
{
"specificationVersion": "jobtemplate-2023-09",
"name": "TimeoutTest",
"parameterDefinitions": [{"name": "J", "type": "STRING"}],
"steps": [
{
"name": "Timeout",
"script": {
"actions": {
"onRun": {
"command": "python",
"args": [
"-c",
# Obfuscate "EXIT_NORMAL" so it doesn't appear in the log when Windows prints the command that's run to the log.
"import time,sys; print('SLEEP'); sys.stdout.flush(); time.sleep(5); print(chr(69)+'XIT_NORMAL')",
],
"timeout": 2,
}
}
},
}
],
},
[], # Env Templates
"Timeout", # step name
[], # Task params
False, # run_dependencies
re.compile(r"SLEEP"),
"EXIT_NORMAL",
True,
id="TaskTimeout",
),
],
)
def test_do_run_success(
Expand Down

0 comments on commit d031a91

Please sign in to comment.