Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added look for completed experiment task fixes #3066 #3135

Merged
merged 2 commits into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -197,3 +197,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