Sha256: 933886aa94c26e6b973c002b5939b2d69ab7e7a32bfbf544189551e0e65c9bed

Contents?: true

Size: 785 Bytes

Versions: 6

Compression:

Stored size: 785 Bytes

Contents

module EventSourcery
  module EventStore
    # Manages shutdown signals and facilitate graceful shutdowns of subscriptions.
    #
    # @see Subscription
    class SignalHandlingSubscriptionMaster
      def initialize
        @shutdown_requested = false
        setup_graceful_shutdown
      end

      # If a shutdown has been requested through a `TERM` or `INT` signal, this will throw a `:stop`
      # (generally) causing a Subscription to stop listening for events.
      #
      # @see Subscription#start
      def shutdown_if_requested
        throw :stop if @shutdown_requested
      end

      private

      def setup_graceful_shutdown
        %i(TERM INT).each do |signal|
          Signal.trap(signal) { @shutdown_requested = true }
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
event_sourcery-0.20.0 lib/event_sourcery/event_store/signal_handling_subscription_master.rb
event_sourcery-0.19.0 lib/event_sourcery/event_store/signal_handling_subscription_master.rb
event_sourcery-0.18.0 lib/event_sourcery/event_store/signal_handling_subscription_master.rb
event_sourcery-0.17.0 lib/event_sourcery/event_store/signal_handling_subscription_master.rb
event_sourcery-0.16.1 lib/event_sourcery/event_store/signal_handling_subscription_master.rb
event_sourcery-0.15.0 lib/event_sourcery/event_store/signal_handling_subscription_master.rb