from typing import Any from database.connection import DatabasePool from registry import input_factories, output_factories class LazyFactory: def __init__(self, module_path: str, class_name: str, options_class_name: str): self.module_path: str = module_path self.class_name: str = class_name self.options_class_name: str = options_class_name def __call__(self, db: DatabasePool, d: dict[str, Any]): module = __import__( self.module_path, fromlist=[self.class_name, self.options_class_name] ) service_class = getattr(module, self.class_name) options_class = getattr(module, self.options_class_name) return service_class(db, options_class.from_dict(d)) def bootstrap(): input_factories["mastodon-wss"] = LazyFactory( "mastodon.input", "MastodonInputService", "MastodonInputOptions" ) input_factories["misskey-wss"] = LazyFactory( "misskey.input", "MisskeyInputService", "MisskeyInputOptions" ) input_factories["bluesky-jetstream"] = LazyFactory( "bluesky.input", "BlueskyJetstreamInputService", "BlueskyJetstreamInputOptions" ) output_factories['stderr'] = LazyFactory( "util.dummy", "StderrOutputService", "DummyOptions" )