Sha256: 20273ada876821460151bb9725736023bd68ac6408ca6456c9927b3d444fccd4

Contents?: true

Size: 659 Bytes

Versions: 1

Compression:

Stored size: 659 Bytes

Contents

require 'worker_killer/memory_limiter'
require 'worker_killer/count_limiter'

module WorkerKiller
  class DelayedJobPlugin

    attr_reader :limiter, :killer, :reaction

    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

    def new(*_args)
      configure_lifecycle(Delayed::Worker.lifecycle)
    end

    def configure_lifecycle(lifecycle)
      lifecycle.after(:perform) do |worker, *_args|
        reaction.call(limiter, killer, worker) if limiter.check
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
worker_killer-0.1.1.39838 lib/worker_killer/delayed_job_plugin.rb