Something went wrong. Try again.
🌉 A bridge between decentralized social networks fed.brid.gy
Something went wrong. Try again.
1.9 kB · 56 lines
Python
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657"""Single-instance hub for ATProto firehose client."""import loggingimport osfrom pathlib import Pathimport threadingfrom threading import Thread
from flask import Flaskfrom oauth_dropins.webutil.appengine_info import DEBUG, LOCAL_SERVERfrom oauth_dropins.webutil import appengine_config, flask_util
# all protocolsimport activitypub, atproto, nostr, webimport atproto_firehoseimport models
# WARNING: when this is higher than 1, we start seeing ndb context exceptions,# "ContextError: No current context," in _handle, even though it has an ndb context# from handler. No clue why. They happen more often as the number of threads# increases. Are ndb clients/contexts not thread safe?!# https://github.com/snarfed/bridgy-fed/issues/1315# https://console.cloud.google.com/errors/detail/CJrBqKnRzPfNRA;time=PT1H;refresh=true;locations=global?project=bridgy-federatedHANDLE_THREADS = 10
logger = logging.getLogger(__name__)
models.reset_protocol_properties()
# Flask appapp = Flask(__name__)app.json.compact = Falseapp_dir = Path(__file__).parentapp.config.from_pyfile(app_dir / 'config.py')
@app.get('/liveness_check')
@app.get('/readiness_check')def health_check(): """App Engine Flex health checks.
https://cloud.google.com/appengine/docs/flexible/reference/app-yaml?tab=python#updated_health_checks """ return 'OK'
# start firehose consumer threadsif LOCAL_SERVER or not DEBUG: threads = [t.name for t in threading.enumerate()] assert 'atproto_firehose.subscriber' not in threads assert 'atproto_firehose.handler' not in threads
Thread(target=atproto_firehose.subscriber, name='atproto_firehose.subscriber', daemon=True).start() for i in range(HANDLE_THREADS): Thread(target=atproto_firehose.handler, name=f'atproto_firehose.handler-{i}', daemon=True).start()