Sha256: e98f6289e685c4880ae11985de82e3268c261fc26612a7510072d6f1cb932e50

Contents?: true

Size: 1.29 KB

Versions: 12

Compression:

Stored size: 1.29 KB

Contents

require "active_support/notifications"

module ActionSubscriber
  module Babou
    ##
    # Class Methods
    #
    def self.start_subscribers
      reload_active_record
      ::ActionSubscriber.setup_default_threadpool!
      ::ActionSubscriber.setup_subscriptions!
      ::ActionSubscriber.print_subscriptions
      ::ActionSubscriber.start_subscribers!
      logger.info "Action Subscriber connected"
      ::ActiveSupport::Notifications.instrument("action_subscriber:server_started")
      while true
        sleep 1.0 #just hang around waiting for messages
        break if shutting_down?
      end

      logger.info "Stopping subscribers..."
      ::ActionSubscriber.stop_subscribers!
      logger.info "Shutting down"
      ::ActionSubscriber::RabbitConnection.subscriber_disconnect!
      logger.info "Shutdown complete"
      ::ActiveSupport::Notifications.instrument("action_subscriber:server_stopped")
      exit(0)
    end

    def self.logger
      ::ActionSubscriber::Logging.logger
    end

    def self.reload_active_record
      if defined?(::ActiveRecord::Base) && !::ActiveRecord::Base.connected?
        ::ActiveRecord::Base.establish_connection
      end
    end

    def self.shutting_down?
      !!@shutting_down
    end

    def self.stop_server!
      @shutting_down = true
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
action_subscriber-5.3.3-java lib/action_subscriber/babou.rb
action_subscriber-5.3.3 lib/action_subscriber/babou.rb
action_subscriber-5.3.2-java lib/action_subscriber/babou.rb
action_subscriber-5.3.2 lib/action_subscriber/babou.rb
action_subscriber-5.3.1-java lib/action_subscriber/babou.rb
action_subscriber-5.3.1 lib/action_subscriber/babou.rb
action_subscriber-5.3.1.pre-java lib/action_subscriber/babou.rb
action_subscriber-5.3.1.pre lib/action_subscriber/babou.rb
action_subscriber-5.3.0-java lib/action_subscriber/babou.rb
action_subscriber-5.3.0 lib/action_subscriber/babou.rb
action_subscriber-5.2.4-java lib/action_subscriber/babou.rb
action_subscriber-5.2.4 lib/action_subscriber/babou.rb