aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--webmentions_ssg/__init__.py30
1 files changed, 29 insertions, 1 deletions
diff --git a/webmentions_ssg/__init__.py b/webmentions_ssg/__init__.py
index f8fd8f1..8fed1a7 100644
--- a/webmentions_ssg/__init__.py
+++ b/webmentions_ssg/__init__.py
@@ -8,6 +8,7 @@ import logging
import logging.handlers
import os
from pathlib import Path
+from urllib.parse import urlsplit
import coloredlogs
from flask import Flask
@@ -75,7 +76,12 @@ def create_app(config_class: type[DefaultConfig] | None = None) -> Flask:
config_class = DevelopmentConfig if development else ProductionConfig
app = Flask(
- __name__, instance_path=str(Path("testing").absolute()) if development else None
+ __name__,
+ instance_path=(
+ str(Path("testing").absolute())
+ if issubclass(config_class, DevelopmentConfig)
+ else None
+ ),
)
app.config.from_object(config_class)
@@ -129,6 +135,28 @@ def create_app(config_class: type[DefaultConfig] | None = None) -> Flask:
"Configure RATELIMIT_STORAGE_URI with shared storage before running in production."
)
+ if not app.testing and not app.debug:
+ # HUEY_URL overrides the legacy HUEY.url option; absent either, Huey
+ # falls back to an in-process queue that cannot serve a separate worker.
+ huey_url = app.config.get(
+ "HUEY_URL", app.config.get("HUEY", {}).get("url", "memory://")
+ )
+ if isinstance(huey_url, str) and urlsplit(huey_url).scheme.lower() in {
+ "memory",
+ "blackhole",
+ }:
+ raise RuntimeError(
+ "Configure HUEY_URL with a shared, persistent queue before "
+ "running in production (memory:// and blackhole:// are unsafe)."
+ )
+
+ # Local development and tests should start from a fresh checkout: their
+ # default log directory and development SQLite instance are generated.
+ if app.testing or app.debug:
+ Path(app.config["LOG_FILE"]).parent.mkdir(parents=True, exist_ok=True)
+ if app.debug:
+ Path(app.instance_path).mkdir(parents=True, exist_ok=True)
+
default_logging_formatter = logging.Formatter(app.config["LOG_FORMAT"])
log_file_handler = logging.handlers.RotatingFileHandler(