Skip to content

Commit d031a91

Browse files
authored
fix: run command exits when an action reaches timeout (#97)
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]>
1 parent f6a54b2 commit d031a91

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/openjd/cli/_run/_local_session/_session_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ def _action_callback(self, session_id: str, new_status: ActionStatus) -> None:
376376
if isinstance(self._current_action, RunTaskAction):
377377
self.tasks_run += 1
378378
self._action_ended.set()
379-
if new_status.state in (ActionState.FAILED, ActionState.CANCELED):
379+
if new_status.state in (ActionState.FAILED, ActionState.CANCELED, ActionState.TIMEOUT):
380380
self.failed = True
381381
self._action_ended.set()
382382

test/openjd/cli/test_run_command.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,39 @@
434434
True,
435435
id="EnvExitFails_2",
436436
),
437+
pytest.param(
438+
{
439+
"specificationVersion": "jobtemplate-2023-09",
440+
"name": "TimeoutTest",
441+
"parameterDefinitions": [{"name": "J", "type": "STRING"}],
442+
"steps": [
443+
{
444+
"name": "Timeout",
445+
"script": {
446+
"actions": {
447+
"onRun": {
448+
"command": "python",
449+
"args": [
450+
"-c",
451+
# Obfuscate "EXIT_NORMAL" so it doesn't appear in the log when Windows prints the command that's run to the log.
452+
"import time,sys; print('SLEEP'); sys.stdout.flush(); time.sleep(5); print(chr(69)+'XIT_NORMAL')",
453+
],
454+
"timeout": 2,
455+
}
456+
}
457+
},
458+
}
459+
],
460+
},
461+
[], # Env Templates
462+
"Timeout", # step name
463+
[], # Task params
464+
False, # run_dependencies
465+
re.compile(r"SLEEP"),
466+
"EXIT_NORMAL",
467+
True,
468+
id="TaskTimeout",
469+
),
437470
],
438471
)
439472
def test_do_run_success(

0 commit comments

Comments
 (0)