Module: Exekutor::Hook

Extended by:
ActiveSupport::Concern
Included in:
Plugins::Appsignal
Defined in:
lib/exekutor/hook.rb

Overview

Defines hooks for Exekutor.

Examples:

Define and register hooks

class ExekutorHooks
  include Exekutor::Hook
  around_job_execution :instrument
  after_job_failure {|_job, error| report_error error }
  after_fatal_error :report_error

  def instrument(job)
    ErrorMonitoring.monitor_transaction { yield }
  end

  def report_error(error)
    ErrorMonitoring.report error
  end
end

Exekutor.hooks.register ExekutorHooks

Instance Method Summary collapse

Instance Method Details

#callbacksHash<Symbol,Array<Proc>>

Gets the registered callbacks

Returns:

  • (Hash<Symbol,Array<Proc>>)

    the callbacks



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/exekutor/hook.rb', line 40

def callbacks
  instance = self
  __callbacks.transform_values do |callbacks|
    callbacks.map do |method, callback|
      if method
        method(method)
      elsif callback.arity.zero?
        -> { instance.instance_exec(&callback) }
      else
        ->(*args) { instance.instance_exec(*args, &callback) }
      end
    end
  end
end