Sha256: b70952215e4035b5f0243af793e6e49c6b722d2192c33c6a08fc85447dc276e0

Contents?: true

Size: 1.02 KB

Versions: 5

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module Delayed
  module Master
    class Worker
      module Plugins
        class SignalHandler < Delayed::Plugin
          callbacks do |lifecycle|
            lifecycle.before(:execute) do |worker|
              worker.instance_eval do
                Signal.trap(:USR1) do
                  Thread.new do
                    master_logger.info { "reopening files..." }
                    Delayed::Master::FileReopener.reopen
                    master_logger.info { "reopened" }
                  end
                end
                Signal.trap(:USR2) do
                  Thread.new do
                    $0 = "#{$0} [OLD]"
                    master_logger.info { "shutting down worker #{Process.pid}..." }
                    stop
                  end
                end
              end
            end
            lifecycle.after(:execute) do |worker|
              worker.master_logger.info { "shut down worker #{Process.pid}" }
            end
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
delayed_job_master-3.1.2 lib/delayed/master/worker/plugins/signal_handler.rb
delayed_job_master-3.1.1 lib/delayed/master/worker/plugins/signal_handler.rb
delayed_job_master-3.1.0 lib/delayed/master/worker/plugins/signal_handler.rb
delayed_job_master-3.0.1 lib/delayed/master/worker/plugins/signal_handler.rb
delayed_job_master-3.0.0 lib/delayed/master/worker/plugins/signal_handler.rb