chore: centralize webhook scheduler interval config

This commit is contained in:
Abhimanyu Saharan
2026-02-14 06:36:09 +00:00
parent 130f2b36f0
commit 9a49768b52
4 changed files with 11 additions and 2 deletions

View File

@@ -24,4 +24,5 @@ WEBHOOK_REDIS_URL=redis://localhost:6379/0
WEBHOOK_QUEUE_NAME=webhook-dispatch
WEBHOOK_DISPATCH_THROTTLE_SECONDS=2.0
WEBHOOK_DISPATCH_SCHEDULE_ID=webhook-dispatch-batch
WEBHOOK_DISPATCH_SCHEDULE_INTERVAL_SECONDS=900
WEBHOOK_DISPATCH_MAX_RETRIES=3

View File

@@ -58,6 +58,7 @@ class Settings(BaseSettings):
webhook_queue_name: str = "webhook-dispatch"
webhook_dispatch_schedule_id: str = "webhook-dispatch-batch"
webhook_dispatch_throttle_seconds: float = 2.0
webhook_dispatch_schedule_interval_seconds: int = 900
webhook_dispatch_max_retries: int = 3
# Logging

View File

@@ -11,7 +11,7 @@ from app.core.config import settings
from app.services.webhooks import dispatch
def bootstrap_webhook_dispatch_schedule(interval_seconds: int = 900) -> None:
def bootstrap_webhook_dispatch_schedule(interval_seconds: int | None = None) -> None:
"""Register a recurring queue-flush job and keep it idempotent."""
connection = Redis.from_url(settings.webhook_redis_url)
scheduler = Scheduler(queue_name=settings.webhook_queue_name, connection=connection)
@@ -20,10 +20,16 @@ def bootstrap_webhook_dispatch_schedule(interval_seconds: int = 900) -> None:
if job.id == settings.webhook_dispatch_schedule_id:
scheduler.cancel(job)
effective_interval_seconds = (
settings.webhook_dispatch_schedule_interval_seconds
if interval_seconds is None
else interval_seconds
)
scheduler.schedule(
datetime.now(tz=timezone.utc) + timedelta(seconds=5),
func=dispatch.run_flush_webhook_delivery_queue,
interval=interval_seconds,
interval=effective_interval_seconds,
repeat=None,
id=settings.webhook_dispatch_schedule_id,
queue_name=settings.webhook_queue_name,

View File

@@ -96,6 +96,7 @@ services:
WEBHOOK_REDIS_URL: redis://redis:6379/0
WEBHOOK_QUEUE_NAME: webhook-dispatch
WEBHOOK_DISPATCH_SCHEDULE_ID: webhook-dispatch-batch
WEBHOOK_DISPATCH_SCHEDULE_INTERVAL_SECONDS: 900
restart: unless-stopped
volumes: