Sha256: e20475ecbbffb745bb15482ee3eb12d50994b6b93cddf343dcc6148f46df8007

Contents?: true

Size: 850 Bytes

Versions: 2

Compression:

Stored size: 850 Bytes

Contents

module SalesforceStreamer
  class Server
    attr_writer :push_topics

    def initialize(push_topics: [])
      @push_topics = push_topics
    end

    def run
      Log.info 'Starting Server'
      catch_signals
      start_em
    end

    private

    def catch_signals
      %w[INT USR1 USR2 TERM TTIN TSTP].each do |sig|
        trap sig do
          puts "Caught signal #{sig}. Shutting down..."
          exit 0
        end
      end
    end

    def client
      Restforce.new.tap(&:authenticate!)
    end

    def start_em
      EM.run do
        @push_topics.map do |topic|
          client.subscribe topic.name, replay: topic.replay.to_i do |msg|
            Log.info "Message received from topic #{topic.name}"
            MessageReceiver.call topic.name, topic.handler_constant, msg
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
salesforce_streamer-0.4.1 lib/salesforce_streamer/server.rb
salesforce_streamer-0.4.0 lib/salesforce_streamer/server.rb