Add pubsub.LiveEventSubscriber (subscribe_to_changes)#7
Merged
Conversation
Port the Java SDK's subscribe_to_changes to Python. New hand-written pubsub/ module (packaged alongside sso/, survives client regeneration since update.sh only touches ./client) that opens a WebSocket to the FastComments live server, hands each parsed LiveEvent to a callback, fetches events missed while disconnected from the event-log endpoint on reconnect, and reconnects with jitter until the caller closes the subscription. - pubsub/live_event_subscriber.py: LiveEventSubscriber.subscribe_to_changes - pubsub/subscribe_to_changes_result.py: SubscribeToChangesResult.close() - pyproject.toml: new "pubsub" optional extra (client + websocket-client); package discovery + coverage include pubsub; dev extra pulls it in - README: usage section + install/import notes - tests/test_pubsub.py: unit tests (WebSocket + event-log API mocked) The EU region event-log fallback uses https://eu.fastcomments.com when region="eu" (unless api_host/api_client is overridden), so missed-event replay queries EU infra for EU tenants instead of silently hitting US.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds live subscription support to the Python SDK, porting the Java SDK's
LiveEventSubscriber/subscribeToChanges. Consumers can now receive real-time comment events (new comments, votes, edits, notifications, etc.) over a WebSocket.How
New hand-written
pubsub/module, packaged alongsidesso/(survives client regeneration sinceupdate.shonly touches./client):pubsub/live_event_subscriber.py—LiveEventSubscriber.subscribe_to_changes(...). Runs the connection on a background daemon thread, transparently reconnects with jitter, and fetches events missed while disconnected from the event-log endpoint on reconnect. Optionalcan_see_commentsvisibility filter,on_connection_status_changecallback,disable_live_commentingshort-circuit, andLiveEventSubscriber.create_testing()for a short NAT-friendly ping interval.pubsub/subscribe_to_changes_result.py—SubscribeToChangesResult.close().pyproject.toml— newpubsuboptional extra (fastcomments[client]+websocket-client>=1.5.0); package discovery and coverage includepubsub;devextra pulls it in.README.md— usage section + install/import notes.EU region fix (baked in)
The event-log fallback defaults its REST host from
region: whenregion="eu"and the caller hasn't overriddenapi_host/api_client, it targetshttps://eu.fastcomments.cominstead of silently querying US infra and getting nothing back. (The Java SDK had the identical bug in its fallback — fixed in FastComments/fastcomments-java#16.)Testing
tests/test_pubsub.py— 11 unit tests, WebSocket and event-log API mocked (no real network): URL/region routing, message dispatch,can_see_commentsfiltering, connection-status callback, intentional-close-prevents-reconnect, event-log missed-event replay, and EU/US/override host selection.Note
websocket-clientrequires Python >= 3.9 while the base package floor is 3.8. It's only pulled in via the optionalpubsubextra, so the base/SSO install (floor 3.8) is unaffected.