@@ -208,17 +208,30 @@ def partial_update(self, request, pk):
208
208
None ,
209
209
description = "The Activation has been deleted." ,
210
210
),
211
+ status .HTTP_409_CONFLICT : OpenApiResponse (
212
+ None ,
213
+ description = "Activation blocked while Workers offline." ,
214
+ ),
211
215
}
212
216
| RedisDependencyMixin .redis_unavailable_response (),
217
+ parameters = [
218
+ OpenApiParameter (
219
+ name = "force" ,
220
+ description = "Force delete after worker node offline" ,
221
+ required = False ,
222
+ type = bool ,
223
+ )
224
+ ],
213
225
)
214
226
def destroy (self , request , * args , ** kwargs ):
215
227
activation = self .get_object ()
228
+ force_delete = str_to_bool (
229
+ request .query_params .get ("force" , "false" ),
230
+ )
216
231
217
- if activation .status == ActivationStatus .WORKERS_OFFLINE :
218
- raise api_exc .Conflict (
219
- f"An Activation in state '{ activation .status } ' cannot be "
220
- "deleted." ,
221
- )
232
+ self ._check_workers_offline_with_force (
233
+ activation , force_delete , "Deleted"
234
+ )
222
235
223
236
audit_log = logging_utils .generate_simple_audit_log (
224
237
"Delete" ,
@@ -434,14 +447,33 @@ def _start(self, request, activation: models.Activation) -> Response:
434
447
None ,
435
448
description = "Activation has been disabled." ,
436
449
),
450
+ status .HTTP_409_CONFLICT : OpenApiResponse (
451
+ None ,
452
+ description = "Activation blocked while Workers offline." ,
453
+ ),
437
454
}
438
455
| RedisDependencyMixin .redis_unavailable_response (),
456
+ parameters = [
457
+ OpenApiParameter (
458
+ name = "force" ,
459
+ description = "Force disable after worker node offline" ,
460
+ required = False ,
461
+ type = bool ,
462
+ )
463
+ ],
439
464
)
440
465
@action (methods = ["post" ], detail = True , rbac_action = Action .DISABLE )
441
466
def disable (self , request , pk ):
442
467
activation = self .get_object ()
443
468
444
469
self ._check_deleting (activation )
470
+ force_disable = str_to_bool (
471
+ request .query_params .get ("force" , "false" ),
472
+ )
473
+
474
+ self ._check_workers_offline_with_force (
475
+ activation , force_disable , "Disabled"
476
+ )
445
477
446
478
if activation .is_enabled :
447
479
# Redis must be available in order to perform the delete.
@@ -509,19 +541,9 @@ def restart(self, request, pk):
509
541
request .query_params .get ("force" , "false" ),
510
542
)
511
543
512
- if (
513
- settings .DEPLOYMENT_TYPE == "podman"
514
- and activation .status == ActivationStatus .WORKERS_OFFLINE
515
- and not force_restart
516
- ):
517
- # block the restart and return an error
518
- raise api_exc .Conflict (
519
- "An activation with an activation_status of 'Workers offline' "
520
- "cannot be Restarted because this will leave an orphaned "
521
- "container running on one of the 'activation-worker-node's. "
522
- "If you want to force a restart, please add the "
523
- "/?force=true query param."
524
- )
544
+ self ._check_workers_offline_with_force (
545
+ activation , force_restart , "Restarted"
546
+ )
525
547
if not activation .is_enabled :
526
548
raise api_exc .Forbidden (
527
549
detail = "Activation is disabled and cannot be run."
@@ -616,6 +638,32 @@ def _check_deleting(self, activation):
616
638
detail = "Object is being deleted" , code = 409
617
639
)
618
640
641
+ def _check_workers_offline_with_force (
642
+ self , activation , force_flag , operation_name
643
+ ):
644
+ """
645
+ Check if activation is in WORKERS_OFFLINE status and handle force flag logic.
646
+
647
+ Args:
648
+ activation: The activation object to check
649
+ force_flag: Boolean indicating if force operation is requested
650
+ operation_name: String name of the operation (e.g., "Restarted", "Disabled", "Deleted")
651
+
652
+ Raises:
653
+ api_exc.Conflict: If activation is WORKERS_OFFLINE and force flag is False
654
+ """
655
+ if (
656
+ activation .status == ActivationStatus .WORKERS_OFFLINE
657
+ and not force_flag
658
+ ):
659
+ raise api_exc .Conflict (
660
+ f"An activation with an activation_status of 'Workers offline' "
661
+ f"cannot be { operation_name } because this may leave an orphaned "
662
+ f"container running. "
663
+ f"If you want to force a { operation_name .lower ()} , please add the "
664
+ f"/?force=true query param."
665
+ )
666
+
619
667
620
668
@extend_schema_view (
621
669
retrieve = extend_schema (
0 commit comments