AshDispatch.Workers.SendWebhook (AshDispatch v0.5.0)

View Source

Oban worker for sending webhooks asynchronously.

This worker:

  1. Fetches the DeliveryReceipt by ID
  2. Marks receipt as :sending
  3. Sends HTTP POST to webhook URL
  4. Marks receipt as :sent or :failed

Usage

Jobs are enqueued automatically by webhook transports (Discord, Slack, generic Webhook):

# Discord transport enqueues job
Discord.deliver(receipt, context, channel, event_config)

# Worker processes job asynchronously
%{
  "receipt_id" => "...",
  "webhook_url" => "https://discord.com/api/webhooks/...",
  "payload" => %{
    "content" => "Order #1234 created",
    "embeds" => [...]
  },
  "headers" => %{
    "Content-Type" => "application/json"
  }
}

Retries

Oban handles retries automatically:

  • Max 5 attempts (configurable)
  • Exponential backoff (configurable)
  • Failed jobs can be manually retried

HTTP Client

Uses Req for HTTP requests with:

  • Automatic retries for network errors
  • Timeout handling (10 seconds default)
  • JSON encoding/decoding
  • Comprehensive error reporting

Webhook Formats

Discord and Slack use different JSON formats:

Discord

{
  "content": "Message text",
  "embeds": [{
    "title": "Order Created",
    "description": "Order #1234",
    "color": 5814783
  }]
}

Slack

{
  "text": "Message text",
  "blocks": [{
    "type": "section",
    "text": {"type": "mrkdwn", "text": "Order #1234"}
  }]
}

Summary

Functions

Processes webhook sending job.

Functions

perform(job)

Processes webhook sending job.

Job Args

  • receipt_id - DeliveryReceipt UUID
  • webhook_url - Full webhook URL
  • payload - JSON payload to send
  • headers - Optional HTTP headers (defaults to JSON content type)

Returns

  • :ok on success (2xx response)
  • {:error, reason} on failure (Oban will retry)