refactor: improve webhook processing with enhanced logging and retry mechanisms

This commit is contained in:
Abhimanyu Saharan
2026-02-15 13:01:33 +05:30
parent e28496245b
commit 7e76cd1f68
8 changed files with 176 additions and 81 deletions

View File

@@ -1,32 +1,43 @@
#!/usr/bin/env python
"""Top-level RQ helper entrypoint."""
"""RQ worker entrypoint."""
from __future__ import annotations
import argparse
import os
import asyncio
import sys
from pathlib import Path
ROOT_DIR = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ROOT_DIR))
BACKEND_ROOT = ROOT_DIR / "backend"
sys.path.insert(0, str(BACKEND_ROOT))
from scripts.rq_webhook import cmd_worker
from app.services.webhooks.dispatch import flush_webhook_delivery_queue
def cmd_worker(args: argparse.Namespace) -> int:
async def _run_forever() -> None:
while True:
await flush_webhook_delivery_queue(
block=True,
block_timeout=0,
)
try:
asyncio.run(_run_forever())
except KeyboardInterrupt:
return 0
return 0
def build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(description="Generic background worker helpers.")
parser = argparse.ArgumentParser(description="RQ background worker helpers.")
subparsers = parser.add_subparsers(dest="command", required=True)
worker_parser = subparsers.add_parser(
"worker",
help="Run background queue worker loop.",
)
worker_parser.add_argument(
"--interval-seconds",
type=float,
default=float(os.environ.get("WEBHOOK_WORKER_INTERVAL_SECONDS", "2")),
help="Seconds to wait for queue work before returning when idle.",
help="Continuously process queued webhook delivery work.",
)
worker_parser.set_defaults(func=cmd_worker)