Class: ApiKeys::Jobs::CallbacksJob

Inherits:
ActiveJob::Base
  • Object
show all
Includes:
Logging
Defined in:
lib/api_keys/jobs/callbacks_job.rb

Overview

Background job to execute configured lifecycle callbacks asynchronously.

Instance Method Summary collapse

Instance Method Details

#perform(callback_type, context = {}) ⇒ Object

Executes the appropriate callback based on the type.

Parameters:

  • callback_type (Symbol)

    :before_authentication or :after_authentication

  • context (Hash) (defaults to: {})

    Serializable context data for the callback.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/api_keys/jobs/callbacks_job.rb', line 20

def perform(callback_type, context = {})
  config = ApiKeys.configuration

  case callback_type
  when :before_authentication
    execute_callback(config.before_authentication, context)
  when :after_authentication
    execute_callback(config.after_authentication, context)
  else
    log_warn "[ApiKeys::Jobs::CallbacksJob] Unknown callback type: #{callback_type}"
  end
rescue StandardError => e
  log_error "[ApiKeys::Jobs::CallbacksJob] Error executing callback #{callback_type} with context #{context.inspect}: #{e.class}: #{e.message}
#{e.backtrace.join("
")}"
  # Avoid retrying callback errors by default, as the original request succeeded.
  # Depending on callback importance, users might configure retries separately.
end