Skip to content

Commit ac7c932

Browse files
fix(core): do not discard operation outputs when shutdown is set (#219)
* fix(core): operation output typing Update typing to reflect that None can be returned by an operation * fix(core): save operation output when shutdown set The code assumed that if shutdown was set when an operation returned there would be no output, but this may not be the case #202 Also the logs assumed that shutdown could only be set by SIGTERM. However because of #200 we cannot for sure if this is the case. Hence the logs are temporarily changed here to reflect this.
1 parent e43209e commit ac7c932

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

orchestrator/modules/operators/_explore_orchestration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def handler(sig, frame):
141141

142142
def run_explore_operation_core_closure(
143143
operator: "OperatorActor", state: "DiscoverySpaceManagerActor"
144-
) -> typing.Callable[[], OperationOutput]:
144+
) -> typing.Callable[[], OperationOutput | None]:
145145

146146
def _run_explore_operation_core() -> OperationOutput:
147147
import numpy as np

orchestrator/modules/operators/_general_orchestration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def run_general_operation_core_closure(
3737
FunctionOperationInfo,
3838
...,
3939
],
40-
OperationOutput,
40+
OperationOutput | None,
4141
],
4242
discovery_space: DiscoverySpace,
4343
operationInfo: FunctionOperationInfo,
@@ -47,7 +47,7 @@ def run_general_operation_core_closure(
4747
def _run_general_operation_core() -> OperationOutput:
4848
return operation_function(
4949
discovery_space, operationInfo, **operation_parameters
50-
) # type: OperationOutput
50+
) # type: OperationOutput | None
5151

5252
return _run_general_operation_core
5353

orchestrator/modules/operators/_orchestrate_core.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def log_space_details(discovery_space: "DiscoverySpace"):
4646

4747

4848
def _run_operation_harness(
49-
run_closure: typing.Callable[[], OperationOutput],
49+
run_closure: typing.Callable[[], OperationOutput | None],
5050
base_operation_configuration: BaseOperationRunConfiguration,
5151
discovery_space: DiscoverySpace,
5252
operation_identifier: str | None = None,
@@ -85,7 +85,7 @@ def _run_operation_harness(
8585
OperationResourceStatus(event=OperationResourceEventEnum.STARTED)
8686
)
8787
discovery_space.metadataStore.updateResource(operation_resource)
88-
operation_output = run_closure()
88+
operation_output: OperationOutput | None = run_closure()
8989
except KeyboardInterrupt:
9090
sys.stdout.flush()
9191
moduleLog.warning("Caught keyboard interrupt - initiating graceful shutdown")
@@ -124,12 +124,19 @@ def _run_operation_harness(
124124
time.sleep(1)
125125
sys.stdout.flush()
126126
if shutdown:
127-
moduleLog.warning("Operation exited normally but a signal was sent")
128-
operation_output = None
129-
operationStatus = OperationResourceStatus(
130-
event=OperationResourceEventEnum.FINISHED,
131-
exit_state=OperationExitStateEnum.ERROR,
132-
message="Operation exited due to SIGTERM)",
127+
moduleLog.warning(
128+
"Operation exited normally but an external event e.g. SIGTERM, has already initiated shutdown"
129+
)
130+
if operation_output:
131+
moduleLog.info("Operation returned output - will save")
132+
133+
operationStatus = (
134+
OperationResourceStatus(
135+
event=OperationResourceEventEnum.FINISHED,
136+
exit_state=OperationExitStateEnum.ERROR,
137+
message="An external event e.g. SIGTERM, initiated shutdown. "
138+
"This may have caused the operation to exit early",
139+
),
133140
)
134141
else:
135142
if not operation_output:

0 commit comments

Comments
 (0)