Files
jobboard/roledesk/web/app.py
T
WolfandClaude Opus 5.5 36dbcbb29e Skeleton: roledesk on desk and pipeline from ../news
Package layers models, config, storage, jobs, web, cli, held by
tests/test_architecture.py with desk and pipeline as external trees and
plugins/ limited to desk. roles.yaml is the default config, roledesk.db
its own file, port 8790. create_app mounts pipeline.web.connect over
Jobs(config.database); `roledesk job pull` drains a no-op pull and
`roledesk db init` creates the file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-23 10:59:17 +02:00

47 lines
1.4 KiB
Python

"""The application factory. A stub page until the reader lands: the queue's
routes and socket from `pipeline.web.connect`, and a one-line index."""
from __future__ import annotations
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
from pipeline import Jobs
from pipeline.web import connect
from roledesk import config as config_mod
from roledesk import jobs
from roledesk.storage import Store
INDEX = """<!doctype html>
<meta charset="utf-8"><title>roledesk</title>
<p>roledesk: no reader yet.</p>
<script type="module" src="/_jobs/jobs.js"></script>
<desk-jobs></desk-jobs>
"""
def create_app(config_path: str | None = None) -> FastAPI:
config = config_mod.load(config_path)
# `Store` first, so the file is at the current schema before the queue
# adds its own table to it.
store = Store(config.database)
app = FastAPI(title="roledesk", docs_url="/api/docs")
connect(app, Jobs(config.database), config, store,
workers=config.workers.model_dump(),
bootstrap=jobs.BOOTSTRAP, bootstrap_arg=config.path or "")
app.state.config = config
app.state.store = store
@app.get("/", response_class=HTMLResponse)
def index() -> str:
return INDEX
return app
def serve(host: str, port: int, config_path: str | None) -> int:
import uvicorn
uvicorn.run(create_app(config_path), host=host, port=port)
return 0