Skip to content

Commit

Permalink
Use changeset endpoint for sync_megaphone job (#1506)
Browse files Browse the repository at this point in the history
  • Loading branch information
leplatrem authored Jan 9, 2025
1 parent 8b6dd98 commit 7b77d4d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
15 changes: 7 additions & 8 deletions commands/sync_megaphone.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import os
import random

import requests.auth

Expand Down Expand Up @@ -52,14 +51,14 @@ def get_version(self):

def get_remotesettings_timestamp(uri):
client = KintoClient(server_url=uri)
random_cache_bust = random.randint(999999000000, 999999999999)
entries = client.get_records(
bucket="monitor", collection="changes", _expected=random_cache_bust
changeset = client.get_changeset(bucket="monitor", collection="changes", bust_cache=True)
# We want to filter out preview entries, because we don't want to notify all clients
# when a review is requested. Therefore we can't use the `timestamp` field and must
# get it from filtered entries.
# https://github.com/mozilla/remote-settings/blob/45841c04/kinto-remote-settings/src/kinto_remote_settings/changes/views.py#L40-L44
return str(
max(e["last_modified"] for e in changeset["changes"] if "preview" not in e["bucket"])
)
# Some collections are excluded (eg. preview)
# https://github.com/mozilla-services/cloudops-deployment/blob/master/projects/kinto/puppet/modules/kinto/templates/kinto.ini.erb
matched = [e for e in entries if "preview" not in e["bucket"]]
return str(matched[0]["last_modified"])


def sync_megaphone(event, context):
Expand Down
8 changes: 4 additions & 4 deletions tests/test_sync_megaphone.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TestSyncMegaphone(unittest.TestCase):

def setUp(self):
self.source_monitor_changes_uri = (
f"{self.server}/buckets/monitor/collections/changes/records"
f"{self.server}/buckets/monitor/collections/changes/changeset"
)
self.megaphone_broadcasts_uri = f"{self.megaphone_url}/broadcasts"
self.megaphone_broadcast_uri = f"{self.megaphone_url}/broadcasts/{self.broadcast_id}"
Expand All @@ -34,7 +34,7 @@ def test_does_nothing_if_up_to_date(self):
responses.GET,
self.source_monitor_changes_uri,
json={
"data": [
"changes": [
{
"id": "a",
"bucket": "main-preview",
Expand Down Expand Up @@ -78,7 +78,7 @@ def test_does_nothing_if_megaphone_is_newer(self):
responses.GET,
self.source_monitor_changes_uri,
json={
"data": [
"changes": [
{
"id": "b",
"bucket": "main",
Expand Down Expand Up @@ -115,7 +115,7 @@ def test_sends_version_if_differs(self):
responses.GET,
self.source_monitor_changes_uri,
json={
"data": [
"changes": [
{
"id": "a",
"bucket": "main",
Expand Down

0 comments on commit 7b77d4d

Please sign in to comment.