add dev-mode
This commit is contained in:
parent
0803617e62
commit
31e1da937f
7 changed files with 146 additions and 51 deletions
31
repub/web.py
31
repub/web.py
|
|
@ -13,7 +13,7 @@ from datastar_py.quart import DatastarResponse, read_signals
|
|||
from datastar_py.sse import DatastarEvent
|
||||
from htpy import Renderable
|
||||
from peewee import IntegrityError
|
||||
from quart import Quart, Response, request, url_for
|
||||
from quart import Quart, Response, request, send_from_directory, url_for
|
||||
|
||||
from repub.datastar import RefreshBroker, render_stream
|
||||
from repub.jobs import (
|
||||
|
|
@ -46,6 +46,7 @@ from repub.pages.sources import PANGEA_CONTENT_FORMATS, PANGEA_CONTENT_TYPES
|
|||
REFRESH_BROKER_KEY = "repub.refresh_broker"
|
||||
JOB_RUNTIME_KEY = "repub.job_runtime"
|
||||
DEFAULT_LOG_DIR = Path("out/logs")
|
||||
DEFAULT_FEEDS_DIR = Path("out/feeds")
|
||||
|
||||
RenderFunction = Callable[[], Awaitable[Renderable]]
|
||||
|
||||
|
|
@ -95,16 +96,27 @@ def _render_shim_page(
|
|||
return body, etag
|
||||
|
||||
|
||||
def create_app() -> Quart:
|
||||
def create_app(*, dev_mode: bool = False) -> Quart:
|
||||
app = Quart(__name__)
|
||||
app.config["REPUB_DB_PATH"] = str(initialize_database())
|
||||
app.config.setdefault("REPUB_LOG_DIR", DEFAULT_LOG_DIR)
|
||||
app.config.setdefault("REPUB_JOB_WORKER_DURATION_SECONDS", 20.0)
|
||||
app.config.setdefault("REPUB_JOB_WORKER_STATS_INTERVAL_SECONDS", 1.0)
|
||||
app.config.setdefault("REPUB_JOB_WORKER_FAILURE_PROBABILITY", 0.3)
|
||||
app.config.setdefault("REPUB_FEEDS_DIR", DEFAULT_FEEDS_DIR)
|
||||
app.config["REPUB_DEV_MODE"] = dev_mode
|
||||
app.extensions[REFRESH_BROKER_KEY] = RefreshBroker()
|
||||
app.extensions[JOB_RUNTIME_KEY] = None
|
||||
|
||||
@app.get("/feeds/<path:feed_path>")
|
||||
async def published_feed(feed_path: str) -> Response:
|
||||
if not bool(app.config["REPUB_DEV_MODE"]):
|
||||
return Response(status=404)
|
||||
response = await send_from_directory(
|
||||
str(Path(app.config["REPUB_FEEDS_DIR"])),
|
||||
feed_path,
|
||||
)
|
||||
if Path(feed_path).suffix == ".rss":
|
||||
response.mimetype = "application/rss+xml"
|
||||
return response
|
||||
|
||||
@app.get("/")
|
||||
@app.get("/sources")
|
||||
@app.get("/sources/create")
|
||||
|
|
@ -257,15 +269,6 @@ def get_job_runtime(app: Quart) -> JobRuntime:
|
|||
if runtime is None:
|
||||
runtime = JobRuntime(
|
||||
log_dir=app.config["REPUB_LOG_DIR"],
|
||||
worker_duration_seconds=float(
|
||||
app.config["REPUB_JOB_WORKER_DURATION_SECONDS"]
|
||||
),
|
||||
worker_stats_interval_seconds=float(
|
||||
app.config["REPUB_JOB_WORKER_STATS_INTERVAL_SECONDS"]
|
||||
),
|
||||
worker_failure_probability=float(
|
||||
app.config["REPUB_JOB_WORKER_FAILURE_PROBABILITY"]
|
||||
),
|
||||
refresh_callback=lambda: trigger_refresh(app),
|
||||
)
|
||||
app.extensions[JOB_RUNTIME_KEY] = runtime
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue