class WorkerKiller::DelayedJobPlugin

Attributes

killer[R]
limiter[R]
reaction[R]

Public Class Methods

new(klass:, killer:, reaction: nil, **opts) click to toggle source
# File lib/worker_killer/delayed_job_plugin.rb, line 9
def initialize(klass:, killer:, reaction: nil, **opts)
  @killer = killer

  @reaction = reaction || proc do |l, k, dj|
    k.kill(l.started_at, dj: dj)
  end

  @limiter = klass.new(opts)
end

Public Instance Methods

configure_lifecycle(lifecycle) click to toggle source
# File lib/worker_killer/delayed_job_plugin.rb, line 23
def configure_lifecycle(lifecycle)
  lifecycle.after(:perform) do |worker, *_args|
    reaction.call(limiter, killer, worker) if limiter.check
  end
end
new(*_args) click to toggle source
# File lib/worker_killer/delayed_job_plugin.rb, line 19
def new(*_args)
  configure_lifecycle(Delayed::Worker.lifecycle)
end