d167be8274
Add REST hooks subscription endpoints, incoming action endpoints, and
Zapier-compatible flat payload format for automation platform integration.
- AutomationHook model for webhook subscriptions
- POST /api/automation/hooks/subscribe and DELETE /hooks/{id}
- GET /api/automation/triggers/sample/{event} for Zapier field mapping
- POST /api/automation/actions/upload for incoming document uploads
- Celery task with retry for async hook delivery
- Integration with existing webhook dispatch flow
- 30 passing tests covering all new functionality
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
"""Celery task for asynchronous automation hook delivery with retry and backoff.
|
|
|
|
Uses :class:`~app.tasks.retry_config.BaseTaskWithRetry` so failed deliveries
|
|
are automatically retried with exponential backoff (default: 60 s, 300 s,
|
|
900 s) and ±20 % jitter.
|
|
"""
|
|
|
|
import logging
|
|
from typing import Any
|
|
|
|
from app.celery_app import celery
|
|
from app.tasks.retry_config import BaseTaskWithRetry
|
|
from app.utils.webhook import deliver_webhook
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@celery.task(base=BaseTaskWithRetry, bind=True, name="automation.deliver_hook")
|
|
def deliver_automation_hook_task(self, url: str, payload: dict[str, Any], secret: str | None = None) -> dict[str, Any]:
|
|
"""Deliver an automation hook payload to *url* with automatic retries.
|
|
|
|
Args:
|
|
url: Target webhook URL (provided by Zapier / Make.com).
|
|
payload: The flat Zapier-compatible payload.
|
|
secret: Optional shared secret for HMAC-SHA256 signing.
|
|
|
|
Returns:
|
|
A dict with ``status`` and ``url`` on success.
|
|
|
|
Raises:
|
|
RuntimeError: Re-raised to trigger Celery retry on delivery failure.
|
|
"""
|
|
logger.info(
|
|
"Delivering automation hook to %s (attempt %d/%d)",
|
|
url,
|
|
self.request.retries + 1,
|
|
self.max_retries + 1,
|
|
)
|
|
|
|
success = deliver_webhook(url, payload, secret)
|
|
if success:
|
|
return {"status": "delivered", "url": url}
|
|
|
|
raise RuntimeError(f"Automation hook delivery to {url} failed")
|