module Bellbro::Hooks::ClassMethods

Public Instance Methods

after(*hooks, &block) click to toggle source

Public: Declare hooks to run after Worker invocation. The after method may be called multiple times; subsequent calls prepend declared hooks to existing after hooks.

hooks - Zero or more Symbol method names representing instance methods

to be called after worker invocation.

block - An optional block to be executed as a hook. If given, the block

is executed before methods corresponding to any given Symbols.

Examples

class MyWorker
  include Worker

  after :set_finish_time

  after do
    puts "finished"
  end

  def call
    puts "called"
  end

  private

  def set_finish_time
    context.finish_time = Time.now
  end
end

Returns nothing.

# File lib/bellbro/hooks.rb, line 147
def after(*hooks, &block)
  hooks << block if block
  hooks.each { |hook| after_hooks.push(hook) }
end
after_hooks() click to toggle source

Internal: An Array of declared hooks to run before Worker invocation. The hooks appear in the order in which they will be run.

Examples

class MyWorker
  include Sidekiq::Worker

  after :set_finish_time, :say_goodbye
end

MyWorker.after_hooks
# => [:say_goodbye, :set_finish_time]

Returns an Array of Symbols and Procs.

# File lib/bellbro/hooks.rb, line 210
def after_hooks
  @after_hooks ||= []
end
always(*hooks, &block) click to toggle source
# File lib/bellbro/hooks.rb, line 152
def always(*hooks, &block)
  hooks << block if block
  hooks.each { |hook| always_hooks.unshift(hook) }
end
always_hooks() click to toggle source
# File lib/bellbro/hooks.rb, line 214
def always_hooks
  @always_hooks ||= []
end
around(*hooks, &block) click to toggle source

Public: Declare hooks to run around worker invocation. The around method may be called multiple times; subsequent calls append declared hooks to existing around hooks.

hooks - Zero or more Symbol method names representing instance methods

to be called around worker invocation. Each instance method
invocation receives an argument representing the next link in
the around hook chain.

block - An optional block to be executed as a hook. If given, the block

is executed after methods corresponding to any given Symbols.

Examples

class MyWorker
  include Worker

  around :time_execution

  around do |worker|
    puts "started"
    worker.call
    puts "finished"
  end

  def call
    puts "called"
  end

  private

  def time_execution(worker)
    context.start_time = Time.now
    worker.call
    context.finish_time = Time.now
  end
end

Returns nothing.

# File lib/bellbro/hooks.rb, line 65
def around(*hooks, &block)
  hooks << block if block
  hooks.each { |hook| around_hooks.push(hook) }
end
around_hooks() click to toggle source

Internal: An Array of declared hooks to run around Worker invocation. The hooks appear in the order in which they will be run.

Examples

class MyWorker
  include Worker

  around :time_execution, :use_transaction
end

MyWorker.around_hooks
# => [:time_execution, :use_transaction]

Returns an Array of Symbols and Procs.

# File lib/bellbro/hooks.rb, line 172
def around_hooks
  @around_hooks ||= []
end
before(*hooks, &block) click to toggle source

Public: Declare hooks to run before Worker invocation. The before method may be called multiple times; subsequent calls append declared hooks to existing before hooks.

hooks - Zero or more Symbol method names representing instance methods

to be called before worker invocation.

block - An optional block to be executed as a hook. If given, the block

is executed after methods corresponding to any given Symbols.

Examples

class MyWorker
  include Worker

  before :set_start_time

  before do
    puts "started"
  end

  def call
    puts "called"
  end

  private

  def set_start_time
    context.start_time = Time.now
  end
end

Returns nothing.

# File lib/bellbro/hooks.rb, line 110
def before(*hooks, &block)
  hooks << block if block
  hooks.each { |hook| before_hooks.push(hook) }
end
before_hooks() click to toggle source

Internal: An Array of declared hooks to run before Worker invocation. The hooks appear in the order in which they will be run.

Examples

class MyWorker
  include Sidekiq::Worker

  before :set_start_time, :say_hello
end

MyWorker.before_hooks
# => [:set_start_time, :say_hello]

Returns an Array of Symbols and Procs.

# File lib/bellbro/hooks.rb, line 191
def before_hooks
  @before_hooks ||= []
end
time_out_in(interval) click to toggle source
# File lib/bellbro/hooks.rb, line 70
def time_out_in(interval)
  @time_out_interval = interval
end
time_out_interval() click to toggle source
# File lib/bellbro/hooks.rb, line 74
def time_out_interval
  @time_out_interval
end