Add federation milestones: scrobble-count, artist-plays, top-10 entries
CI / validate-monitoring (push) Successful in 9s
CI / lint (push) Successful in 15s
CI / federation-interop (push) Successful in 1m1s
CI / test (push) Successful in 3m7s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Failing after 2m31s
CI / validate-monitoring (push) Successful in 9s
CI / lint (push) Successful in 15s
CI / federation-interop (push) Successful in 1m1s
CI / test (push) Successful in 3m7s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Failing after 2m31s
Adds publishing/milestones.py: one post per check, in priority order (scrobble count > top-10 entry > artist plays), each threshold marked done the first time it's reached so it's never posted twice. A live scrobble queues a per-user FederationPendingCheck row (collapsing repeats so the event receiver stays fast); the new federation.milestones worker task drains it, requeuing to the back of the queue on failure rather than retrying immediately, since a milestone check is a pure DB read with no external server to fail against. Enabling sharing, and finishing an import, call set_baseline() instead of a live check: every threshold already passed is marked done without posting, so history already on file never produces a burst of retroactive "milestone" posts. Wired into sharing.update()'s enable-toggle branch with a local import, mirroring farewell_user()'s existing precedent for the same sharing<->federation-internals circularity. A top-10 entry now requires the user to actually have TOP_N distinct artists first - caught by a test with unpatched thresholds, where every first play of a new artist was trivially "entering an empty top 10". Fixes test_federation_boundary.py's off-means-off check: blinker signals are process-wide, so once any app in the test process enables federation the milestone receivers stay connected for the rest of the run regardless of which app is "current" - there's no per-app scoping to introspect. Replaced the receiver-absence assertion with a behavioural one (firing an event through the off app's own context is a no-op), and kept the existing per-app-scoped view/worker checks as they were. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
This commit is contained in:
1 parent
0766c09fb3
commit
c3a8233e73
5 files changed
+603
-4
No files matched your search
@@ -36,12 +36,21 @@ def init_app(app: Flask) -> None:
|
||||
core_api.register_blueprint(api.blp, url_prefix="/api/v1/federation")
|
||||
openapi.register(app, core_api)
|
||||
|
||||
from scrobbler import worker
|
||||
from scrobbler import events, worker
|
||||
from scrobbler.federation import delivery, inbox
|
||||
from scrobbler.federation.publishing import weekly
|
||||
from scrobbler.federation.publishing import milestones, weekly
|
||||
|
||||
worker.register_task(app, "federation.inbox", inbox.work_once)
|
||||
worker.register_task(app, "federation.deliver", delivery.work_once)
|
||||
worker.register_task(app, "federation.milestones", milestones.work_once)
|
||||
worker.register_periodic(app, "federation.inbox.maintenance", 300, inbox.maintenance)
|
||||
worker.register_periodic(app, "federation.gauges", 30, delivery.maintenance)
|
||||
worker.register_periodic(app, "federation.weekly", 900, weekly.check_all)
|
||||
|
||||
# blinker signals are process-wide, not per-app: once any app in a process enables
|
||||
# federation these stay connected for every app in it, including one built with
|
||||
# federation off (see test_federation_boundary.py for why "off" is instead enforced
|
||||
# by each receiver checking its own app's config). weak=False because the receivers
|
||||
# are plain module functions meant to live as long as the process does.
|
||||
events.scrobbles_stored.connect(milestones.on_scrobbles_stored, weak=False)
|
||||
events.import_finished.connect(milestones.on_import_finished, weak=False)
|
||||
Reference in new issue
Block a user