@@ -555,13 +555,31 @@ class Filters:
555555 publish_status = NimbusConstants .PublishStatus .WAITING ,
556556 )
557557 IS_UPDATE_QUEUED = Q (
558- status = NimbusConstants .Status .LIVE ,
559- status_next = NimbusConstants .Status .LIVE ,
558+ Q (
559+ status = NimbusConstants .Status .LIVE ,
560+ status_next__in = (
561+ NimbusConstants .Status .LIVE ,
562+ NimbusConstants .Status .DISABLED ,
563+ ),
564+ )
565+ | Q (
566+ status = NimbusConstants .Status .DISABLED ,
567+ status_next = NimbusConstants .Status .LIVE ,
568+ ),
560569 publish_status = NimbusConstants .PublishStatus .APPROVED ,
561570 )
562571 IS_UPDATING = Q (
563- status = NimbusConstants .Status .LIVE ,
564- status_next = NimbusConstants .Status .LIVE ,
572+ Q (
573+ status = NimbusConstants .Status .LIVE ,
574+ status_next__in = (
575+ NimbusConstants .Status .LIVE ,
576+ NimbusConstants .Status .DISABLED ,
577+ ),
578+ )
579+ | Q (
580+ status = NimbusConstants .Status .DISABLED ,
581+ status_next = NimbusConstants .Status .LIVE ,
582+ ),
565583 publish_status = NimbusConstants .PublishStatus .WAITING ,
566584 )
567585 IS_END_QUEUED = Q (
@@ -1285,7 +1303,10 @@ def advance_rollout_phase(self):
12851303 today = timezone .now ().date ()
12861304 phase_ids = [phase .id for phase in phases ]
12871305
1288- if self .rollout_phase_id is None :
1306+ if self .rollout_phase_next_id is not None :
1307+ current_phase = self .rollout_phase
1308+ next_phase = self .rollout_phase_next
1309+ elif self .rollout_phase_id is None :
12891310 current_phase = None
12901311 next_phase = phases [0 ]
12911312 else :
@@ -1297,7 +1318,9 @@ def advance_rollout_phase(self):
12971318 if next_phase is not None and not next_phase .population_percent :
12981319 return
12991320
1300- if current_phase is not None :
1321+ if current_phase is not None and (
1322+ current_phase .end_date is None or current_phase .end_date > today
1323+ ):
13011324 current_phase .end_date = today
13021325 if current_phase .actual_start_date :
13031326 current_phase .start_date = current_phase .actual_start_date
@@ -1312,8 +1335,59 @@ def advance_rollout_phase(self):
13121335 next_phase .save ()
13131336 self .rollout_phase = next_phase
13141337 self .rollout_phase_next = None
1338+ self .population_percent = next_phase .population_percent
13151339 self .save ()
13161340
1341+ def stage_rollout_phase_advance (self , copy_current_if_missing = False ):
1342+ phases = list (self .rollout_phases .all ())
1343+ if not phases :
1344+ return None
1345+
1346+ current_phase = self .rollout_phase
1347+ if self .rollout_phase_next_id is not None :
1348+ next_phase = self .rollout_phase_next
1349+ elif self .rollout_phase_id is None :
1350+ next_phase = phases [0 ]
1351+ else :
1352+ phase_ids = [phase .id for phase in phases ]
1353+ current_index = phase_ids .index (self .rollout_phase_id )
1354+ next_index = current_index + 1
1355+ next_phase = phases [next_index ] if next_index < len (phases ) else None
1356+
1357+ if next_phase is None and copy_current_if_missing and current_phase is not None :
1358+ next_phase = self .rollout_phases .create (
1359+ population_percent = current_phase .population_percent
1360+ )
1361+
1362+ if next_phase is None or not next_phase .population_percent :
1363+ return None
1364+
1365+ self .rollout_phase_next = next_phase
1366+ self .population_percent = next_phase .population_percent
1367+ self .save (update_fields = ["rollout_phase_next" , "population_percent" ])
1368+ return next_phase
1369+
1370+ def end_current_rollout_phase (self ):
1371+ current_phase = self .rollout_phase
1372+ if current_phase is None :
1373+ return
1374+
1375+ today = timezone .now ().date ()
1376+ if current_phase .end_date is not None and current_phase .end_date <= today :
1377+ return
1378+
1379+ current_phase .end_date = today
1380+ if current_phase .actual_start_date :
1381+ current_phase .start_date = current_phase .actual_start_date
1382+ current_phase .save ()
1383+
1384+ def disable_rollout (self ):
1385+ if self .is_rollout :
1386+ self .population_percent = 0
1387+ self .save ()
1388+ else :
1389+ raise ValueError ("Cannot disable rollout for a non-rollout experiment." )
1390+
13171391 @property
13181392 def is_missing_takeaway_info (self ):
13191393 return (
0 commit comments