Module: Desiru::Jobs::Webhookable

Defined in:
lib/desiru/jobs/webhook_notifier.rb

Overview

Mixin to add webhook support to jobs

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



144
145
146
147
# File 'lib/desiru/jobs/webhook_notifier.rb', line 144

def self.included(base)
  base.extend(ClassMethods)
  base.instance_variable_set(:@webhook_config, WebhookConfig.new)
end

.prepended(base) ⇒ Object



149
150
151
152
# File 'lib/desiru/jobs/webhook_notifier.rb', line 149

def self.prepended(base)
  base.extend(ClassMethods)
  base.instance_variable_set(:@webhook_config, WebhookConfig.new)
end

Instance Method Details

#perform(*args) ⇒ Object



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/desiru/jobs/webhook_notifier.rb', line 154

def perform(*args)
  job_id = args.first || "job-#{Time.now.to_i}"
  result = nil
  error = nil
  status = :completed

  begin
    # Call the original perform method
    result = super
  rescue StandardError => e
    error = e
    status = :failed
    raise # Re-raise to maintain normal error handling
  ensure
    # Send webhook notification if configured
    send_webhook_notification(job_id, status, result, error) if should_notify_webhook?(status)
  end

  result
end