Configurable logging for the API and worker (SCR-5)
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
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>
This commit is contained in:
1 parent
65cd610468
commit
ad383b602e
16 files changed
+212
-7
No files matched your search
+28
-2
@@ -50,18 +50,44 @@ def registered(app: Flask | None = None) -> list[str]:
|
||||
|
||||
|
||||
def _call(task: _Task) -> bool:
|
||||
started = time.monotonic()
|
||||
try:
|
||||
worked = bool(task.fn())
|
||||
result = task.fn()
|
||||
except Exception:
|
||||
log.exception("worker task %s failed", task.name)
|
||||
log.exception(
|
||||
"worker task %s failed after %.0f ms",
|
||||
task.name,
|
||||
_elapsed_ms(started),
|
||||
extra={"task": task.name, "outcome": "error", "duration_ms": _elapsed_ms(started)},
|
||||
)
|
||||
db.session.rollback()
|
||||
metrics.worker_tasks_total.labels(task=task.name, outcome="error").inc()
|
||||
return False
|
||||
worked = bool(result)
|
||||
if worked or task.every is not None:
|
||||
metrics.worker_tasks_total.labels(task=task.name, outcome="worked").inc()
|
||||
duration = _elapsed_ms(started)
|
||||
# Queue tasks are polled every couple of seconds, so only passes that did work are
|
||||
# worth an INFO line; periodic tasks say so only when they report work (a truthy result).
|
||||
log.log(
|
||||
logging.INFO if worked else logging.DEBUG,
|
||||
"worker task %s %s in %.0f ms",
|
||||
task.name,
|
||||
"worked" if worked else "ran (nothing to do)",
|
||||
duration,
|
||||
extra={
|
||||
"task": task.name,
|
||||
"outcome": "worked" if worked else "idle",
|
||||
"duration_ms": duration,
|
||||
},
|
||||
)
|
||||
return worked
|
||||
|
||||
|
||||
def _elapsed_ms(started: float) -> float:
|
||||
return round((time.monotonic() - started) * 1000, 1)
|
||||
|
||||
|
||||
def run_once() -> bool:
|
||||
"""One pass: due periodic tasks, then each queue task once. True if any queue
|
||||
task did work (so there may be more waiting)."""
|
||||
|
||||
Reference in new issue
Block a user