Skip to content

Commit

Permalink
reconnect jetstream websocket after disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Oct 23, 2024
1 parent d21d220 commit 8d9f950
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ def jetstream():
host = os.environ['JETSTREAM_HOST']
logger.info(f'connecting to jetstream at {host}')

ws = simple_websocket.Client(f'wss://{host}/subscribe?wantedCollections=app.bsky.feed.post&wantedCollections=app.bsky.actor.profile')
jetstream_url = f'wss://{host}/subscribe?wantedCollections=app.bsky.feed.post&wantedCollections=app.bsky.actor.profile'
ws = simple_websocket.Client(jetstream_url)
while True:
try:
msg = json.loads(ws.receive())
Expand Down Expand Up @@ -130,9 +131,11 @@ def jetstream():

except simple_websocket.ConnectionClosed as cc:
logger.info(f'reconnecting after jetstream disconnect: {cc}')
ws = simple_websocket.Client(jetstream_url)

except BaseException as err:
if PROD:
# TODO: maybe reconnect?
error_reporting_client.report_exception()
else:
raise
Expand Down

0 comments on commit 8d9f950

Please sign in to comment.