Use Hypercorn for republisher serve

This commit is contained in:
Abel Luck 2026-03-31 12:47:36 +02:00
parent 73617cd40c
commit c04efeb189
7 changed files with 133 additions and 9 deletions

View file

@ -55,6 +55,7 @@ REFRESH_BROKER_KEY = "repub.refresh_broker"
JOB_RUNTIME_KEY = "repub.job_runtime"
TAB_STATE_STORE_KEY = "repub.tab_state_store"
TAB_STATE_CLEANER_TASK_KEY = "repub.tab_state_cleaner_task"
SHUTDOWN_EVENT_KEY = "repub.shutdown_event"
DEFAULT_LOG_DIR = Path("out/logs")
DEFAULT_FEEDS_DIR = Path("out/feeds")
RUNS_TAB_STATE_KEY = "runs"
@ -146,6 +147,7 @@ def create_app(*, dev_mode: bool = False) -> Quart:
app.extensions[JOB_RUNTIME_KEY] = None
app.extensions[TAB_STATE_STORE_KEY] = TabStateStore()
app.extensions[TAB_STATE_CLEANER_TASK_KEY] = None
app.extensions[SHUTDOWN_EVENT_KEY] = None
@app.get("/feeds/<path:feed_path>")
async def published_feed(feed_path: str) -> Response:
@ -402,6 +404,10 @@ def get_refresh_broker(app: Quart) -> RefreshBroker:
return cast(RefreshBroker, app.extensions[REFRESH_BROKER_KEY])
def get_shutdown_event(app: Quart) -> asyncio.Event | None:
return cast(asyncio.Event | None, app.extensions.get(SHUTDOWN_EVENT_KEY))
def get_tab_state_store(app: Quart) -> TabStateStore:
return cast(TabStateStore, app.extensions[TAB_STATE_STORE_KEY])
@ -545,6 +551,7 @@ async def _page_patch_response(
queue,
render=lambda: render(tab_id),
last_event_id=request.headers.get("last-event-id"),
shutdown_event=get_shutdown_event(app),
)
return DatastarResponse(_unsubscribe_on_close(queue, stream, app, tab_id=tab_id))