메일 알림 시스템 추가
This commit is contained in:
parent
ddf12a851c
commit
3bf38c50df
22 changed files with 1769 additions and 31 deletions
44
scripts/run-notification-worker.py
Normal file
44
scripts/run-notification-worker.py
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
"""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())
|
||||
Loading…
Add table
Add a link
Reference in a new issue