videogen/apps/api/app/workers/tasks_lifecycle_mail.py
caelum0x d56639a594
Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Menivor — open source release (MIT), free to use and fork
Paid, hosted product at menivor.com, now retired as a company project.
Fresh squashed history of the cleaned working tree (secret-scanned,
no .env, no customer data, no outreach logs). Built on
MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
2026-12-04 02:10:26 +03:00

50 lines
1.5 KiB
Python

"""Money lifecycle mail sweep (MG5): payment failed, Autopilot paused, credits low.
Importing this module also subscribes the "Autopilot paused" mail to MN1's
``channel_paused`` signal in the worker process (where the beat-driven runner
runs), so a pause is mailed at once; the sweep catches anything missed.
Registration (hand-off to M1.5, the sole Wave B owner of ``celery_app.py``): add
``"app.workers.tasks_lifecycle_mail"`` to ``include`` and a beat entry::
"lifecycle-mail-sweep": {
"task": "app.workers.tasks_lifecycle_mail.lifecycle_mail_sweep_task",
"schedule": 900.0,
},
``MENIVOR_LIFECYCLE_MAIL=0`` turns the sweep off. Never raises.
"""
from __future__ import annotations
import os
from loguru import logger
from app.services.billing import lifecycle_mail
from app.workers.celery_app import celery_app
lifecycle_mail.install()
def sweep_enabled() -> bool:
return (os.environ.get("MENIVOR_LIFECYCLE_MAIL") or "1").strip().lower() not in {"0", "false", "off"}
def lifecycle_mail_sweep() -> dict[str, int]:
if not sweep_enabled():
return {}
try:
return lifecycle_mail.sweep()
except Exception as exc: # noqa: BLE001 - a beat tick must never crash the worker
logger.error(f"lifecycle mail sweep failed: {exc}")
return {}
@celery_app.task(name="app.workers.tasks_lifecycle_mail.lifecycle_mail_sweep_task")
def lifecycle_mail_sweep_task() -> dict[str, int]:
return lifecycle_mail_sweep()
__all__ = ["lifecycle_mail_sweep", "lifecycle_mail_sweep_task", "sweep_enabled"]