@@ -190,6 +190,8 @@ def run_experiment(experiment: Experiment,
190190 initialize_global_controls (experiment , config , secrets , settings )
191191 initialize_controls (experiment , config , secrets )
192192 activity_pool , rollback_pool = get_background_pools (experiment )
193+ rollback_strategy = settings .get ("runtime" , {}).get (
194+ "rollbacks" , {}).get ("strategy" , "default" )
193195
194196 experiment ["title" ] = substitute (experiment ["title" ], config , secrets )
195197 logger .info ("Running experiment: {t}" .format (t = experiment ["title" ]))
@@ -254,6 +256,34 @@ def run_experiment(experiment: Experiment,
254256 "leaving without applying rollbacks." )
255257 else :
256258 journal ["status" ] = journal ["status" ] or "completed"
259+
260+ has_deviated = journal ["deviated" ]
261+ journal_status = journal ["status" ]
262+ play_rollbacks = False
263+ if rollback_strategy == "always" :
264+ logger .warning (
265+ "Rollbacks were explicitly requested to be played" )
266+ play_rollbacks = True
267+ elif rollback_strategy == "never" :
268+ logger .warning (
269+ "Rollbacks were explicitly requested to not be played" )
270+ play_rollbacks = False
271+ elif rollback_strategy == "default" and \
272+ journal_status not in ["failed" , "interrupted" ]:
273+ play_rollbacks = True
274+ elif rollback_strategy == "deviated" :
275+ if has_deviated :
276+ logger .warning (
277+ "Rollbacks will be played only because the experiment "
278+ "deviated" )
279+ play_rollbacks = True
280+ else :
281+ logger .warning (
282+ "Rollbacks werre explicitely requested to be played only "
283+ "if the experiment deviated. Since this is not the case, "
284+ "we will not play them." )
285+
286+ if play_rollbacks :
257287 try :
258288 journal ["rollbacks" ] = apply_rollbacks (
259289 experiment , config , secrets , rollback_pool , dry )
@@ -269,8 +299,7 @@ def run_experiment(experiment: Experiment,
269299 journal ["end" ] = datetime .utcnow ().isoformat ()
270300 journal ["duration" ] = time .time () - started_at
271301
272- has_deviated = journal ["deviated" ]
273- status = "deviated" if has_deviated else journal ["status" ]
302+ status = "deviated" if has_deviated else journal_status
274303
275304 logger .info (
276305 "Experiment ended with status: {s}" .format (s = status ))
0 commit comments