1a195a96bd
- Merge origin/main into branch (resolve conflict in integrations_dashboard.html) - Add defensive JSON parsing with try/except for integration.config - Wrap tester() call in try/except to prevent 500 errors from bad config - Add i18n key integrations.connection_test_failed_fallback in en.json - Reference i18n key in template JS fallback message - Update SECURITY_AUDIT.md: add fix date (2026-03-23), update doc date - Remove accidental revert.sh file - Fix missing MagicMock/patch imports in test file - Add tests for invalid JSON config and tester exception error paths Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com> Agent-Logs-Url: https://github.com/christianlouis/DocuElevate/sessions/daebb70e-059a-4601-8864-88eef49f99cf
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")
|