salesforce_streamer 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb2a264193dc13244ad48222544789f305e483baf9a632ffeb6917f72056b5a7
4
- data.tar.gz: 0bd3ebadf44a12a7adfa56e07cf1fea47dfe390688df85906a4587e188e3b18c
3
+ metadata.gz: 155a5949eb2fb6112f66bed9c87ee95b2936dcb29a384cba1e82016aaed9ce7c
4
+ data.tar.gz: 78f9eda54ef8b075b84446bb80d0f675356a62c3866c7b20dccbafb8480f92f2
5
5
  SHA512:
6
- metadata.gz: 93986c2fdebc68687bf690a87b3cb1dc542685e5a1db839711d0d925ad78a85d9190a44e818788397bc71d98cb038efa63b4e4dd7138045c832f3ddaff8e3245
7
- data.tar.gz: c4d9af017d24f23576b03a88fbd6ca637770fda340154cb9d0085f7461994c28a3127a819b26d2b0fa3a2db1fbb5cf97ecfd43d46ba7029d13e81db56220ef8b
6
+ metadata.gz: 8d86b2c5c246c2ad74ccb6d8201e59c61f211cd8cdf6fdcbe1f16d01ce2ed8641b0256f4058e3a90ea961d95b0cb6bff3fc3bb8e450540c1848c93ff3bd2aa05
7
+ data.tar.gz: 91c093c56e46853485770e5688767d1eae5b1821984546c9acd8b240b945775981707a0f4411092f455cb3b6f69635bd2e4427e7f100ef05d2d8ffed134233c5
@@ -6,7 +6,6 @@ module SalesforceStreamer
6
6
  # starting the server.
7
7
  class Launcher
8
8
  def initialize
9
- @logger = Configuration.instance.logger
10
9
  load_server_configuration
11
10
  @manager = TopicManager.new push_topics: @push_topics
12
11
  @server = Server.new push_topics: @push_topics
@@ -14,7 +13,7 @@ module SalesforceStreamer
14
13
 
15
14
  # Manages each PushTopic configured and starts the Streaming API listener.
16
15
  def run
17
- @logger.info 'Launching Streamer Services'
16
+ Log.info 'Launching Streamer Services'
18
17
  @manager.run
19
18
  @server.push_topics = @manager.push_topics
20
19
  @server.run
@@ -29,16 +28,16 @@ module SalesforceStreamer
29
28
 
30
29
  def require_application
31
30
  if Configuration.instance.require_path
32
- @logger.debug 'Loading the require path'
31
+ Log.debug 'Loading the require path'
33
32
  require Configuration.instance.require_path
34
33
  end
35
34
  end
36
35
 
37
36
  def initialize_push_topics
38
- @logger.debug 'Loading and validating PushTopics configuration'
37
+ Log.debug 'Loading and validating PushTopics configuration'
39
38
  @push_topics = []
40
39
  Configuration.instance.push_topic_data.values.each do |topic_data|
41
- @logger.debug topic_data.to_s
40
+ Log.debug topic_data.to_s
42
41
  @push_topics << PushTopic.new(data: topic_data)
43
42
  end
44
43
  end
@@ -0,0 +1,13 @@
1
+ module SalesforceStreamer
2
+ class Log
3
+ class << self
4
+ extend Forwardable
5
+
6
+ def_delegators :instance, :debug, :info, :warn, :error, :critical
7
+
8
+ def instance
9
+ @instance ||= Configuration.instance.logger
10
+ end
11
+ end
12
+ end
13
+ end
@@ -20,7 +20,7 @@ module SalesforceStreamer
20
20
 
21
21
  def replay
22
22
  @replay ||= (ReplayPersistence.retrieve(name) || @static_replay).tap do |replayId|
23
- Configuration.instance.logger.info ['PushTopic name=', name, ' starting at replayId=', replayId].join
23
+ Log.info "PushTopic name=#{name} starting at replayId=#{replayId}"
24
24
  end
25
25
  end
26
26
 
@@ -6,13 +6,13 @@ module SalesforceStreamer
6
6
  class ReplayPersistence
7
7
  class << self
8
8
  def record(key, value)
9
- Configuration.instance.logger.debug ['Recording ', key, '=', value].join
9
+ Log.debug { "Recording #{key}=value" }
10
10
  Configuration.instance.persistence_adapter&.record key, value
11
11
  end
12
12
 
13
13
  def retrieve(key)
14
14
  Configuration.instance.persistence_adapter&.retrieve(key).tap do |v|
15
- Configuration.instance.logger.debug ['Retrieved for ', key, ' ', v || 'nil'].join
15
+ Log.debug { "Retrieved for #{key} #{ v || 'nil' }" }
16
16
  end
17
17
  end
18
18
  end
@@ -5,14 +5,13 @@ module SalesforceStreamer
5
5
  attr_writer :push_topics
6
6
 
7
7
  def initialize(push_topics: [])
8
- @logger = Configuration.instance.logger
9
8
  @push_topics = push_topics
10
9
  @client = Restforce.new
11
10
  end
12
11
 
13
12
  def run
14
13
  @client.authenticate!
15
- @logger.info 'Starting Server'
14
+ Log.info 'Starting Server'
16
15
  catch_signals
17
16
  start_em
18
17
  end
@@ -32,6 +31,7 @@ module SalesforceStreamer
32
31
  EM.run do
33
32
  @push_topics.map do |topic|
34
33
  @client.subscribe topic.name, replay: topic.replay.to_i do |msg|
34
+ Log.info "Message received from topic #{topic.name}"
35
35
  MessageReceiver.call topic.name, topic.handler_constant, msg
36
36
  end
37
37
  end
@@ -6,14 +6,13 @@ module SalesforceStreamer
6
6
 
7
7
  def initialize(push_topics:)
8
8
  @push_topics = push_topics
9
- @logger = Configuration.instance.logger
10
9
  @client = SalesforceClient.new
11
10
  end
12
11
 
13
12
  def run
14
- @logger.info 'Running Topic Manager'
13
+ Log.info 'Running Topic Manager'
15
14
  @push_topics.each do |push_topic|
16
- @logger.debug push_topic.to_s
15
+ Log.debug push_topic.to_s
17
16
  upsert(push_topic) if diff?(push_topic)
18
17
  end
19
18
  end
@@ -23,25 +22,25 @@ module SalesforceStreamer
23
22
  def diff?(push_topic)
24
23
  hashie = @client.find_push_topic_by_name(push_topic.name)
25
24
  unless hashie
26
- @logger.info "New PushTopic #{push_topic.name}"
25
+ Log.info "New PushTopic #{push_topic.name}"
27
26
  return true
28
27
  end
29
- @logger.debug "Remote PushTopic found with hash=#{hashie.to_h}"
28
+ Log.debug "Remote PushTopic found with hash=#{hashie.to_h}"
30
29
  push_topic.id = hashie.Id
31
30
  return true unless push_topic.query.eql?(hashie.Query)
32
31
  return true unless push_topic.notify_for_fields.eql?(hashie.NotifyForFields)
33
32
  return true unless push_topic.api_version.to_s.eql?(hashie.ApiVersion.to_s)
34
33
 
35
- @logger.debug 'No differences detected'
34
+ Log.debug 'No differences detected'
36
35
  false
37
36
  end
38
37
 
39
38
  def upsert(push_topic)
40
- @logger.info "Upsert PushTopic #{push_topic.name}"
39
+ Log.info "Upsert PushTopic #{push_topic.name}"
41
40
  if Configuration.instance.manage_topics?
42
41
  @client.upsert_push_topic(push_topic)
43
42
  else
44
- @logger.info 'Skipping upsert because manage topics is off'
43
+ Log.info 'Skipping upsert because manage topics is off'
45
44
  end
46
45
  end
47
46
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SalesforceStreamer
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.1'
5
5
  end
@@ -5,9 +5,11 @@ require 'logger'
5
5
  require 'optparse'
6
6
  require 'restforce'
7
7
  require 'yaml'
8
+ require 'forwardable'
8
9
 
9
10
  require 'salesforce_streamer/configuration'
10
11
  require 'salesforce_streamer/errors'
12
+ require 'salesforce_streamer/log'
11
13
  require 'salesforce_streamer/push_topic'
12
14
  require 'salesforce_streamer/topic_manager'
13
15
  require 'salesforce_streamer/salesforce_client'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: salesforce_streamer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Serok
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-19 00:00:00.000000000 Z
11
+ date: 2019-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -134,6 +134,7 @@ files:
134
134
  - lib/salesforce_streamer/configuration.rb
135
135
  - lib/salesforce_streamer/errors.rb
136
136
  - lib/salesforce_streamer/launcher.rb
137
+ - lib/salesforce_streamer/log.rb
137
138
  - lib/salesforce_streamer/message_receiver.rb
138
139
  - lib/salesforce_streamer/push_topic.rb
139
140
  - lib/salesforce_streamer/redis_replay.rb