salesforce_streamer 2.0.0 → 2.1.0

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: 10b71d8f30b4e9eedff2ecabc48ec52d71f276abec73808f80c87d810d3307bb
4
- data.tar.gz: 377f0fcaf7ccf7c44d1eaf615c12fd9e9e6b5f0fb981cd3e8268db4190c7cb23
3
+ metadata.gz: b7aa51a1aab875d18d027a1686a598d795d30126cea6fc81f08e705911bdc92c
4
+ data.tar.gz: ce9f47fdc1f3c277347c684fc533e92e56e93779c3115a0894f8834c1196b795
5
5
  SHA512:
6
- metadata.gz: 59b6418e352e58af09b4e7ba6068bebed370af67feb896d3f0bba73ca1a8741b0bf73d3e67f2ad5dfe0c846694de311e877f0732672d6525cc565b93ffe507c7
7
- data.tar.gz: 6d4d7dfd2baeb69fb0e7c1487a6ded133a7ab9ec4bcbd6c43a4615ceadeadd2b52df780719bef5a7fa34d96d9fed962a8c2a8d916b1e558c62657c0c4948983e
6
+ metadata.gz: 6d7183472e280c49188c8f0a386ddf24e47ee99cd827b0e1b9bb3c22184136ef81694364020a4c6676f728317af530e5959908fe79d871ba065d43f29b0c5f97
7
+ data.tar.gz: 329f63f5ced7e03256761765e70a3d13107779fa895e249e69e07e98d148ed1142b0f23c9e8cc86d38faae92087af59080524cef60a70ba51619ab4ec9cdd36b
@@ -3,6 +3,38 @@
3
3
  Sorted so that the most recent change logs are near the top. Only significant
4
4
  changes are logged in the change log.
5
5
 
6
+ ## 2020-08-17 Scott Serok [scott@renofi.com](mailto:scott@renofi.com)
7
+
8
+ v2.1 changes the expected interface of `Configuration#replay_adapter`.
9
+
10
+ Normally this breaking change would require a major version bump, but since the
11
+ functionality today is quiet broken we can call this a major bug fix.
12
+
13
+ The `config.replay_adapter` should be an object that has an interface like Hash.
14
+ It must respond to `[]` and `[]=`. By default the adapter is an empty hash. If
15
+ you want your push topic replayId to persist between restarts, then you should
16
+ implement a class with an appropriate interface.
17
+
18
+ ```ruby
19
+ class MyReplayAdapter
20
+ def [](channel)
21
+ MyPersistence.get(channel)
22
+ end
23
+
24
+ def []=(channel, replay_id)
25
+ MyPersistence.set(channel, replay_id)
26
+ end
27
+ end
28
+ ```
29
+
30
+ This change was sparked by a misunderstanding of the
31
+ `Restforce::Concerns::Streaming::ReplayExtension` replay handlers.
32
+ SalesforceStreamer can eliminate some complexity and fix a bug by delegating the
33
+ responsibility of maintaining the current replayId to that ReplayExtension. The
34
+ object will be used on each request/response cycle to record and read the latest
35
+ replayId as long as the object assigned to `config.replay_adapter` responds to
36
+ `[]` and `[]=`.
37
+
6
38
  ## 2020-08-04 Scott Serok [scott@renofi.com](mailto:scott@renofi.com)
7
39
 
8
40
  v2.0 is released as a major simplification of this library. There are 2
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- salesforce_streamer (2.0.0)
4
+ salesforce_streamer (2.1.0)
5
5
  dry-initializer (~> 3.0)
6
6
  faye (~> 1.4)
7
7
  restforce (>= 4.2, < 6.0)
data/README.md CHANGED
@@ -89,9 +89,7 @@ Configure the `SalesforceStreamer` module.
89
89
  SalesforceStreamer.configure do |config|
90
90
  config.logger = Logger.new(STDERR, level: 'INFO')
91
91
  config.exception_adapter = proc { |e| puts e }
92
- config.replay_adapter = proc { |topic|
93
- (ReplayStore.get(topic.name) || topic.replay).to_i
94
- }
92
+ config.replay_adapter = MyReplayAdapter
95
93
  config.use_middleware AfterMessageReceived
96
94
  config.manage_topics = true
97
95
  end
@@ -153,6 +151,28 @@ end
153
151
 
154
152
  SalesforceStreamer.config.use_middleware MySimpleMiddleware
155
153
  ```
154
+
155
+ ### ReplayAdapter
156
+
157
+ The `config.replay_adapter` should be an object that has an interface like Hash.
158
+ It must respond to `[]` and `[]=`. By default the adapter is an empty hash. If
159
+ you want your push topic replayId to persist between restarts, then you should
160
+ implement a class with an appropriate interface.
161
+
162
+ ```ruby
163
+ class MyReplayAdapter
164
+ def [](channel)
165
+ Persistence.get(channel)
166
+ end
167
+
168
+ def []=(channel, replay_id)
169
+ Persistence.set(channel, replay_id)
170
+ end
171
+ end
172
+ ```
173
+
174
+ This adapter will be used directly by `Restforce::ReplayExtension`.
175
+
156
176
  ## Development
157
177
 
158
178
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -32,7 +32,7 @@ module SalesforceStreamer
32
32
  end
33
33
 
34
34
  o.on '-v', '--verbose LEVEL', 'Set the log level (default no logging)' do |arg|
35
- @config.logger = Logger.new(STDERR, level: arg)
35
+ @config.logger = Logger.new($stderr, level: arg)
36
36
  end
37
37
 
38
38
  o.on '-V', '--version', 'Print the version information' do
@@ -21,7 +21,7 @@ module SalesforceStreamer
21
21
  @environment = ENV['RACK_ENV'] || :development
22
22
  @logger = Logger.new(IO::NULL)
23
23
  @exception_adapter = proc { |exc| fail(exc) }
24
- @replay_adapter = proc { |topic| topic.id || topic.replay }
24
+ @replay_adapter = Hash.new { |hash, key| hash[key] = -1 }
25
25
  @manage_topics = false
26
26
  @config_file = './config/streamer.yml'
27
27
  @require_path = './config/environment'
@@ -34,7 +34,7 @@ module SalesforceStreamer
34
34
  @handler = Object.const_get(@handler)
35
35
  true
36
36
  rescue NameError, TypeError => e
37
- message = 'handler=' + @handler.to_s + ' exception=' + e.to_s
37
+ message = "handler=#{@handler} exception=#{e}"
38
38
  raise(PushTopicHandlerMissingError, message)
39
39
  end
40
40
 
@@ -8,10 +8,8 @@ module SalesforceStreamer
8
8
  @client.authenticate!
9
9
  end
10
10
 
11
- def subscribe(*args)
12
- @client.subscribe(args) do
13
- yield
14
- end
11
+ def subscribe(*args, &block)
12
+ @client.subscribe(args, &block)
15
13
  end
16
14
 
17
15
  # Returns nil or an instance of Restforce::SObject
@@ -34,12 +34,9 @@ module SalesforceStreamer
34
34
  def start_em
35
35
  EM.run do
36
36
  @push_topics.map do |topic|
37
- replay_id = Configuration.instance.replay_adapter.call(topic)
38
- client.subscribe topic.name, replay: replay_id.to_i do |message|
39
- replay_id = message.dig('event', 'replayId')
40
- Log.info "Message #{replay_id} received from topic #{topic.name}"
37
+ client.subscribe topic.name, replay: Configuration.instance.replay_adapter do |message|
38
+ Log.info "Message #{message.dig('event', 'replayId')} received from topic #{topic.name}"
41
39
  topic.handle message
42
- topic.id = replay_id
43
40
  end
44
41
  end
45
42
  end
@@ -1,3 +1,3 @@
1
1
  module SalesforceStreamer
2
- VERSION = '2.0.0'.freeze
2
+ VERSION = '2.1.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: salesforce_streamer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Serok
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-08-14 00:00:00.000000000 Z
12
+ date: 2020-08-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dry-initializer