Skip to content

Commit

Permalink
added look for completed experiment task fixes mozilla#3066
Browse files Browse the repository at this point in the history
  • Loading branch information
tiftran committed Jul 28, 2020
1 parent 13a39a4 commit b4ebc04
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
30 changes: 30 additions & 0 deletions app/experimenter/kinto/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,33 @@ def check_experiment_is_live():
logger.info("Experiment Status is set to Live")

metrics.incr("check_experiment_is_live.completed")


@app.task
@metrics.timer_decorator("check_experiment_is_complete")
def check_experiment_is_complete():
metrics.incr("check_experiment_is_complete.started")

live_experiments = Experiment.objects.filter(
type=Experiment.TYPE_RAPID, status=Experiment.STATUS_LIVE
)

records = client.get_main_records()
record_ids = [r.get("id") for r in records]

for experiment in live_experiments:
if experiment.normandy_slug not in record_ids:
logger.info(
"{experiment} status is being updated to complete".format(
experiment=experiment
)
)
update_experiment_with_change_log(
experiment,
{"status": Experiment.STATUS_COMPLETE},
settings.KINTO_DEFAULT_CHANGELOG_USER,
)

logger.info("Experiment Status is set to complete")

metrics.incr("check_experiment_is_complete.completed")
58 changes: 58 additions & 0 deletions app/experimenter/kinto/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,61 @@ def test_experiment_updates_when_recipe_is_in_main(self):
new_status=Experiment.STATUS_LIVE,
).exists()
)


class TestCheckExperimentIsComplete(MockKintoClientMixin, TestCase):
def test_experiment_updates_when_recipe_is_not_in_main(self):
experiment1 = ExperimentFactory.create_with_status(
Experiment.STATUS_LIVE,
bugzilla_id="12345",
firefox_channel=Experiment.CHANNEL_RELEASE,
firefox_max_version=None,
firefox_min_version=Experiment.VERSION_CHOICES[0][0],
name="test",
type=Experiment.TYPE_RAPID,
)

experiment2 = ExperimentFactory.create_with_status(
Experiment.STATUS_LIVE,
bugzilla_id="99999",
firefox_channel=Experiment.CHANNEL_RELEASE,
firefox_max_version=None,
firefox_min_version=Experiment.VERSION_CHOICES[0][0],
name="test1",
type=Experiment.TYPE_RAPID,
)

experiment3 = ExperimentFactory.create_with_status(
Experiment.STATUS_DRAFT,
bugzilla_id="54321",
firefox_channel=Experiment.CHANNEL_RELEASE,
firefox_max_version=None,
firefox_min_version=Experiment.VERSION_CHOICES[0][0],
name="test2",
type=Experiment.TYPE_RAPID,
)

self.assertEqual(experiment1.changes.count(), 5)
self.assertEqual(experiment2.changes.count(), 5)
self.assertEqual(experiment3.changes.count(), 1)

self.setup_kinto_get_main_records()
tasks.check_experiment_is_complete()

self.assertEqual(experiment3.changes.count(), 1)

self.assertFalse(
experiment1.changes.filter(
changed_by__email=settings.KINTO_DEFAULT_CHANGELOG_USER,
old_status=Experiment.STATUS_LIVE,
new_status=Experiment.STATUS_COMPLETE,
).exists()
)

self.assertTrue(
experiment2.changes.filter(
changed_by__email=settings.KINTO_DEFAULT_CHANGELOG_USER,
old_status=Experiment.STATUS_LIVE,
new_status=Experiment.STATUS_COMPLETE,
).exists()
)
4 changes: 4 additions & 0 deletions app/experimenter/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@
"task": "experimenter.kinto.tasks.check_experiment_is_live",
"schedule": config("CELERY_SCHEDULE_INTERVAL", default=300, cast=int),
},
"check_experiment_is_complete": {
"task": "experimenter.kinto.tasks.check_experiment_is_complete",
"schedule": config("CELERY_SCHEDULE_INTERVAL", default=300, cast=int),
},
}

# Normandy Configuration
Expand Down

0 comments on commit b4ebc04

Please sign in to comment.