CI / notify (push) Successful in 6s
CI / lint (push) Successful in 18s
CI / test (push) Successful in 5m26s
CI / validate-monitoring (push) Successful in 15s
CI / federation-interop (push) Successful in 1m17s
CI / images (push) Successful in 33s
CI / assets (push) Successful in 9s
CI / python-package (push) Successful in 18s
CI / trigger-deploy (push) Successful in 3s
Shared LOG_LEVEL/LOG_FORMAT (text or json) set up in create_app, per-task activity and duration logs in the worker, and more context on delivery, inbox and import failures. Alembic's fileConfig no longer disables loggers. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
import logging
|
|
|
|
import click
|
|
from flask import current_app
|
|
from flask.cli import AppGroup, with_appcontext
|
|
|
|
|
|
def _run_worker(once: bool, poll: float, serve_metrics: bool) -> None:
|
|
from scrobbler import worker
|
|
|
|
if serve_metrics:
|
|
from scrobbler.metrics.server import start_metrics_server
|
|
|
|
start_metrics_server(current_app.config["WORKER_METRICS_PORT"])
|
|
logging.getLogger(__name__).info("worker tasks: %s", ", ".join(worker.registered()))
|
|
worker.run(poll_seconds=poll, once=once)
|
|
|
|
|
|
def _worker_options(fn):
|
|
fn = click.option(
|
|
"--metrics/--no-metrics", "serve_metrics", default=True, help="Serve Prometheus metrics."
|
|
)(fn)
|
|
fn = click.option(
|
|
"--poll", default=2.0, show_default=True, help="Seconds between checks when idle."
|
|
)(fn)
|
|
return click.option("--once", is_flag=True, help="Do all waiting work, then exit.")(fn)
|
|
|
|
|
|
@click.command("worker")
|
|
@_worker_options
|
|
@with_appcontext
|
|
def worker_command(once: bool, poll: float, serve_metrics: bool) -> None:
|
|
"""Run background work: imports, and tasks registered by optional modules."""
|
|
_run_worker(once, poll, serve_metrics)
|
|
|
|
|
|
imports_cli = AppGroup("imports", help="History imports.")
|
|
|
|
|
|
@imports_cli.command("worker")
|
|
@_worker_options
|
|
def imports_worker(once: bool, poll: float, serve_metrics: bool) -> None:
|
|
"""Alias for `flask worker` (kept for existing deployments)."""
|
|
_run_worker(once, poll, serve_metrics)
|