Class: WebhookProcessorWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
app/workers/webhook_processor_worker.rb

Overview

Worker to process incoming webhooks from the webhook_logs table.
Follows the "ingest then process" pattern for reliable webhook handling.

This worker:

  1. Picks up a WebhookLog entry by ID
  2. Delegates to the appropriate processor based on provider/category
  3. Updates the log state (processed, retry, or exception)

The worker can be triggered:

  • Immediately after a webhook is received
  • By a scheduled job processing pending logs
  • Manually for reprocessing

Examples:

Queue processing for a specific log

WebhookProcessorWorker.perform_async(webhook_log.id)

Instance Method Summary collapse

Instance Method Details

#perform(webhook_log_id) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/workers/webhook_processor_worker.rb', line 24

def perform(webhook_log_id)
  webhook_log = WebhookLog.find_by(id: webhook_log_id)

  unless webhook_log
    Rails.logger.warn "[WebhookProcessorWorker] WebhookLog #{webhook_log_id} not found"
    return
  end

  Rails.logger.info "[WebhookProcessorWorker] Processing WebhookLog #{webhook_log_id} (#{webhook_log.provider}/#{webhook_log.category})"

  # The WebhookLog#process! method handles state transitions and error handling
  webhook_log.process!

  Rails.logger.info "[WebhookProcessorWorker] WebhookLog #{webhook_log_id} now in state: #{webhook_log.state}"
end