def update_launched_experiments(): metrics.incr("update_launched_experiments.started") logger.info("Updating launched experiments info") launched_experiments = Experiment.objects.filter( status__in=[Experiment.STATUS_ACCEPTED, Experiment.STATUS_LIVE] ) for experiment in launched_experiments: try: logger.info("Updating Experiment: {}".format(experiment)) if experiment.normandy_id: recipe_data = normandy.get_recipe(experiment.normandy_id) if needs_to_be_updated(recipe_data, experiment.status): experiment = update_status_task(experiment, recipe_data) if experiment.status == Experiment.STATUS_LIVE: add_start_date_comment_task.delay(experiment.id) send_experiment_launch_email(experiment) elif experiment.status == Experiment.STATUS_COMPLETE: comp_experiment_update_res_task.delay(experiment.id) if experiment.status == Experiment.STATUS_LIVE: update_population_percent(experiment, recipe_data) set_is_paused_value_task.delay(experiment.id, recipe_data) send_period_ending_emails_task(experiment) else: logger.info( "Skipping Experiment: {}. No Normandy id found".format(experiment) ) except (IntegrityError, KeyError, normandy.NormandyError) as e: logger.info(f"Failed to update Experiment {experiment}: {e}") metrics.incr("update_launched_experiments.failed") metrics.incr("update_launched_experiments.completed")
def test_update_status_task(self): experiment = ExperimentFactory.create_with_status( target_status=Experiment.STATUS_ACCEPTED) recipe_data = normandy.get_recipe(experiment.normandy_id) tasks.update_status_task(experiment, recipe_data) experiment = Experiment.objects.get(id=experiment.id) self.assertEqual(experiment.status, Experiment.STATUS_LIVE) self.assertTrue( experiment.changes.filter( changed_by__email="*****@*****.**", old_status=Experiment.STATUS_ACCEPTED, new_status=Experiment.STATUS_LIVE, ).exists())
def test_experiment_with_re_enabled_enrollment(self): experiment = ExperimentFactory.create_with_status( target_status=Experiment.STATUS_LIVE, normandy_id=1234, is_paused=True ) self.mock_normandy_requests_get.return_value = ( self.buildMockSucessWithNoPauseEnrollment() ) recipe_data = normandy.get_recipe(experiment.normandy_id) tasks.set_is_paused_value_task(experiment.id, recipe_data) experiment = Experiment.objects.get(normandy_id=1234) self.assertEqual(experiment.status, Experiment.STATUS_LIVE) self.assertFalse(experiment.is_paused) self.assertEquals(experiment.changes.latest().message, "Enrollment Re-enabled")
def test_set_is_paused_value_task(self): experiment = ExperimentFactory.create_with_status( target_status=Experiment.STATUS_ACCEPTED, normandy_id=12345) recipe_data = normandy.get_recipe(experiment.normandy_id) tasks.set_is_paused_value_task(experiment.id, recipe_data) experiment = Experiment.objects.get(id=experiment.id) self.assertTrue(experiment.is_paused) self.assertTrue( experiment.changes.filter( changed_by__email=settings.NORMANDY_DEFAULT_CHANGELOG_USER, message="Enrollment Completed", ))