44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
"""Drain queued Vignette email notifications once.
|
|
|
|
Use from Task Scheduler, cron, or a one-shot ops shell after SMTP env is loaded.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import asyncio
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
API_ROOT = ROOT / "apps" / "api"
|
|
if str(API_ROOT) not in sys.path:
|
|
sys.path.insert(0, str(API_ROOT))
|
|
|
|
|
|
async def main_async(argv: list[str]) -> int:
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--limit", type=int, default=25, help="Maximum deliveries to process.")
|
|
args = parser.parse_args(argv)
|
|
|
|
from app.db import close_pool, init_pool
|
|
from app.services.notifications import ensure_notification_tables, process_queued_email_notifications
|
|
|
|
await init_pool()
|
|
try:
|
|
await ensure_notification_tables()
|
|
result = await process_queued_email_notifications(limit=args.limit)
|
|
print(json.dumps(result, ensure_ascii=False, sort_keys=True))
|
|
return 1 if result.get("failed", 0) else 0
|
|
finally:
|
|
await close_pool()
|
|
|
|
|
|
def main() -> int:
|
|
return asyncio.run(main_async(sys.argv[1:]))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|