Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -567,12 +567,21 @@ def get_rs_timestamp():
current_timestamp_diff_seconds = int(
(current_rs_timestamp - last_published_timestamp) / 1000
)
current_timestamp_age_seconds = (
utcnow()
- datetime.fromtimestamp(current_rs_timestamp / 1000, timezone.utc)
).total_seconds()
# We publish only if more than `min_debounce_interval` seconds have passed since the last published change.
# or if the current timestamp is already older than the debounce interval.
# (eg. in case of a change that happened a while ago but we haven't published yet).
if current_timestamp_diff_seconds > min_debounce_interval:
log_msg += (
f"Last is {current_timestamp_diff_seconds}s old. Publish!"
)
debounced_timestamp = current_rs_timestamp
elif current_timestamp_age_seconds > min_debounce_interval:
log_msg += f"Last is {current_timestamp_age_seconds}s old. Publish!"
debounced_timestamp = current_rs_timestamp
else:
log_msg += f"It's too close to previously broadcasted {current_timestamp_diff_seconds}s ago."
else:
Expand Down
10 changes: 5 additions & 5 deletions kinto-remote-settings/tests/changes/test_broadcasts.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,15 @@ def test_return_cache_version_if_latest_changes_are_older_than_min_debounce(

assert self.get_broadcasted_version() == f'"{latest_timestamp}"'

def test_return_current_version_if_latest_changes_are_older_than_min_debounce(
def test_publishes_if_latest_changes_are_older_than_min_debounce(
self,
):
"""
==o==x======>>>
==x==o======>>>
| |
| +----> latest timestamp (6 min ago, but 2 min diff with previous, too close)
| +----> latest timestamp (2min diff with previous, but no new in the last 6 minutes), publish!
|
+-------> latest published (8 min ago > min debounce)
+-------> latest published (8 min ago)
"""
latest_timestamp = int(
(FAKE_NOW - datetime.timedelta(minutes=6)).timestamp() * 1000
Expand All @@ -198,4 +198,4 @@ def test_return_current_version_if_latest_changes_are_older_than_min_debounce(
)
self.monitored_timestamps.return_value = [("main", "cid", latest_timestamp)]

assert self.get_broadcasted_version() == f'"{cache_timestamp}"'
assert self.get_broadcasted_version() == f'"{latest_timestamp}"'
Loading