def nimbus_update_experiment_in_kinto(collection, experiment_id): """ An invoked task that given a single experiment id, reserializes and updates the record. If it fails for any reason, log the error and reraise it so it will be forwarded to sentry. """ metrics.incr("update_experiment_in_kinto.started") try: experiment = NimbusExperiment.objects.get(id=experiment_id) logger.info(f"Updating {experiment.slug} in Kinto") kinto_client = KintoClient(collection) data = NimbusExperimentSerializer(experiment).data kinto_client.update_record(data) experiment.publish_status = NimbusExperiment.PublishStatus.WAITING experiment.save() generate_nimbus_changelog( experiment, get_kinto_user(), message=NimbusChangeLog.Messages.UPDATED_IN_KINTO, ) logger.info(f"{experiment.slug} updated in Kinto") metrics.incr("update_experiment_in_kinto.completed") except Exception as e: metrics.incr("update_experiment_in_kinto.failed") logger.info( f"Updating experiment {experiment.slug} in Kinto failed: {e}") raise e
def test_update_record_updates_record_patches_collection( self, review, status): client = KintoClient(self.collection, review=review) data = {"id": "my-record", "field": "value"} client.update_record(data) self.mock_kinto_client.update_record.assert_called_with( data=data, collection=self.collection, bucket=settings.KINTO_BUCKET_WORKSPACE, if_match='"0"', ) self.mock_kinto_client.patch_collection.assert_called_with( id=self.collection, data={"status": status}, bucket=settings.KINTO_BUCKET_WORKSPACE, )