Sha256: 586d07db3ab3eb8e71a2edfbefffa322b499965e6015de4ca2b6ca9db18acd89

Contents?: true

Size: 1.06 KB

Versions: 7

Compression:

Stored size: 1.06 KB

Contents

# vim:fileencoding=utf-8

module Resque
  module Scheduler
    module SignalHandling
      attr_writer :signal_queue

      def signal_queue
        @signal_queue ||= []
      end

      # For all signals, set the shutdown flag and wait for current
      # poll/enqueuing to finish (should be almost instant).  In the
      # case of sleeping, exit immediately.
      def register_signal_handlers
        (Signal.list.keys & %w(INT TERM USR1 USR2 QUIT)).each do |sig|
          trap(sig) do
            signal_queue << sig
            # break sleep in the primary scheduler thread, allowing
            # the signal queue to get processed as soon as possible.
            @th.wakeup if @th && @th.alive?
          end
        end
      end

      def handle_signals
        loop do
          sig = signal_queue.shift
          break unless sig
          log! "Got #{sig} signal"
          case sig
          when 'INT', 'TERM', 'QUIT' then shutdown
          when 'USR1' then print_schedule
          when 'USR2' then reload_schedule!
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
resque-scheduler-4.10.2 lib/resque/scheduler/signal_handling.rb
resque-scheduler-4.10.1 lib/resque/scheduler/signal_handling.rb
resque-scheduler-4.10.0 lib/resque/scheduler/signal_handling.rb
resque-scheduler-4.9.0 lib/resque/scheduler/signal_handling.rb
resque-scheduler-4.8.0 lib/resque/scheduler/signal_handling.rb
resque-scheduler-4.7.0 lib/resque/scheduler/signal_handling.rb
resque-scheduler-4.6.0 lib/resque/scheduler/signal_handling.rb