342
342
343
343
use super :: {
344
344
ACTION_GENERATE_ID , ActionRegistry , NexusActionContext , NexusSaga ,
345
- SagaInitError ,
345
+ SagaContext , SagaInitError ,
346
346
} ;
347
347
use crate :: app:: db:: datastore:: InstanceGestalt ;
348
348
use crate :: app:: db:: datastore:: VmmStateUpdateResult ;
@@ -1307,37 +1307,7 @@ async fn siu_chain_successor_saga(
1307
1307
"instance_id" => %instance_id,
1308
1308
) ;
1309
1309
} else {
1310
- // If the instance has transitioned to the `Failed` state and no
1311
- // additional update saga is required, check if the instance's
1312
- // auto-restart policy allows it to be automatically restarted. If
1313
- // it does, activate the instance-reincarnation background task to
1314
- // automatically restart it.
1315
- let karmic_state = new_state
1316
- . instance
1317
- . auto_restart_status ( new_state. active_vmm . as_ref ( ) ) ;
1318
- if karmic_state. should_reincarnate ( ) {
1319
- info ! (
1320
- log,
1321
- "instance update: instance transitioned to Failed, \
1322
- but can be automatically restarted; activating \
1323
- reincarnation.";
1324
- "instance_id" => %instance_id,
1325
- "auto_restart_config" => ?new_state. instance. auto_restart,
1326
- "runtime_state" => ?new_state. instance. runtime_state,
1327
- "intended_state" => %new_state. instance. intended_state,
1328
- ) ;
1329
- nexus. background_tasks . task_instance_reincarnation . activate ( ) ;
1330
- } else {
1331
- debug ! (
1332
- log,
1333
- "instance update: instance will not reincarnate" ;
1334
- "instance_id" => %instance_id,
1335
- "auto_restart_config" => ?new_state. instance. auto_restart,
1336
- "needs_reincarnation" => karmic_state. needs_reincarnation,
1337
- "karmic_state" => ?karmic_state. can_reincarnate,
1338
- "intended_state" => %new_state. instance. intended_state,
1339
- )
1340
- }
1310
+ reincarnate_if_needed ( osagactx, & new_state)
1341
1311
}
1342
1312
1343
1313
Ok :: < ( ) , anyhow:: Error > ( ( ) )
@@ -1361,6 +1331,43 @@ async fn siu_chain_successor_saga(
1361
1331
Ok ( ( ) )
1362
1332
}
1363
1333
1334
+ fn reincarnate_if_needed ( osagactx : & SagaContext , state : & InstanceGestalt ) {
1335
+ // If the instance has transitioned to the `Failed` state and no
1336
+ // additional update saga is required, check if the instance's
1337
+ // auto-restart policy allows it to be automatically restarted. If
1338
+ // it does, activate the instance-reincarnation background task to
1339
+ // automatically restart it.
1340
+ let karmic_state =
1341
+ state. instance . auto_restart_status ( state. active_vmm . as_ref ( ) ) ;
1342
+ if karmic_state. should_reincarnate ( ) {
1343
+ info ! (
1344
+ & osagactx. log( ) ,
1345
+ "instance update: instance transitioned to Failed, \
1346
+ but can be automatically restarted; activating \
1347
+ reincarnation.";
1348
+ "instance_id" => %state. instance. id( ) ,
1349
+ "auto_restart_config" => ?state. instance. auto_restart,
1350
+ "runtime_state" => ?state. instance. runtime_state,
1351
+ "intended_state" => %state. instance. intended_state,
1352
+ ) ;
1353
+ osagactx
1354
+ . nexus ( )
1355
+ . background_tasks
1356
+ . task_instance_reincarnation
1357
+ . activate ( ) ;
1358
+ } else {
1359
+ debug ! (
1360
+ & osagactx. log( ) ,
1361
+ "instance update: instance will not reincarnate" ;
1362
+ "instance_id" => %state. instance. id( ) ,
1363
+ "auto_restart_config" => ?state. instance. auto_restart,
1364
+ "needs_reincarnation" => karmic_state. needs_reincarnation,
1365
+ "karmic_state" => ?karmic_state. can_reincarnate,
1366
+ "intended_state" => %state. instance. intended_state,
1367
+ )
1368
+ }
1369
+ }
1370
+
1364
1371
/// Unlock the instance record while unwinding.
1365
1372
///
1366
1373
/// This is factored out of the actual reverse action, because the `Params` type
0 commit comments