salesforce_streamer 2.2.0 → 2.3.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: 1b4745cb1c8f38229ac4be01e746a7b865458c37e0d293f3505bfe9803cce20c
4
- data.tar.gz: 290378a24b830fedd86290a06deaf5050fd1187c22467cadc6b1278aee19cebf
3
+ metadata.gz: 76475a30dc6515e8071504a9383c2811fa339f0885be703929008aaf2abbed8d
4
+ data.tar.gz: 927f5ff453fc8e51adaeae3915ee4ace4b0bcf11e355fc66c5aa32dbb5eec3aa
5
5
  SHA512:
6
- metadata.gz: 228d3f363b0b0bb292e94c4776c74fd8930f616250664fb586cfafa2695fcdde07f754f850c430e87ec12b9473046d733975d4c5ac3f9d9e70fd6be0ef8baa73
7
- data.tar.gz: '0850171e7c9762b7cf498a8c9066b21482cab7e69f30d7a72d9cc0ca7b12c90ab5ea167ae312614d6d25060558cfd7aa2a880f60e6d7eaacf8229e916e14c61b'
6
+ metadata.gz: cf695ae8cf24912b2ccb403b46b3151cc9ec988202ed9dd04857dab27cbef4d9afec3425898384649bc1c5bc84e5a68d515237b20f0b0a249ebe92251d51cebf
7
+ data.tar.gz: 0b36d256fdc82499c701aa619205c0dddf3d8837200c1e1575f144fd87caed132658e3137d3c3bc9d655157086a5e6fa2b805561729b7cef50e19a526265ef1d
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- salesforce_streamer (2.2.0)
4
+ salesforce_streamer (2.3.0)
5
5
  dry-initializer (~> 3.0)
6
6
  faye (~> 1.4)
7
7
  restforce (>= 4.2, < 6.0)
data/README.md CHANGED
@@ -183,8 +183,23 @@ out more about extensions from
183
183
  specs.
184
184
 
185
185
  Any configured extensions are added to the Faye client used by the Restforce
186
- client when starting up the server.
186
+ client when starting up the server. If the extension responds to `.server=` then
187
+ the instance of `SalesforceStreamer::Server` is assigned. This may be convenient
188
+ to restart the server subscriptions if an error requires a reset.
187
189
 
190
+ ```ruby
191
+ class MyRestartFayeExtension
192
+ attr_accessor :server
193
+
194
+ def incoming(message, callback)
195
+ callback.call(message).tap |message|
196
+ server.restart if message['error'] == 'tragic'
197
+ end
198
+ end
199
+ end
200
+
201
+ SalesforceStreamer.config.use_faye_extension MyRestartFayeExtension.new
202
+ ```
188
203
  ## Development
189
204
 
190
205
  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.
@@ -1,15 +1,23 @@
1
1
  module SalesforceStreamer
2
2
  class Server
3
3
  attr_writer :push_topics
4
+ attr_reader :client
4
5
 
5
6
  def initialize(push_topics: [])
6
7
  @push_topics = push_topics
7
8
  end
8
9
 
9
10
  def run
10
- Log.info 'Starting Server'
11
+ Log.info 'Starting server'
11
12
  catch_signals
12
- start_em
13
+ reset_client
14
+ EM.run { subscribe }
15
+ end
16
+
17
+ def restart
18
+ Log.info 'Restarting server'
19
+ reset_client
20
+ EM.next_tick { subscribe }
13
21
  end
14
22
 
15
23
  private
@@ -23,24 +31,21 @@ module SalesforceStreamer
23
31
  end
24
32
  end
25
33
 
26
- def client
27
- return @client if @client
34
+ def reset_client
28
35
  @client = Restforce.new
29
- @client.authenticate!
36
+ client.authenticate!
30
37
  Configuration.instance.faye_extensions.each do |extension|
31
38
  Log.debug %(adding Faye extension #{extension})
32
- @client.faye.add_extension extension
39
+ extension.server = self if extension.respond_to?(:server=)
40
+ client.faye.add_extension extension
33
41
  end
34
- @client
35
42
  end
36
43
 
37
- def start_em
38
- EM.run do
39
- @push_topics.map do |topic|
40
- client.subscribe topic.name, replay: Configuration.instance.replay_adapter do |message|
41
- Log.info "Message #{message.dig('event', 'replayId')} received from topic #{topic.name}"
42
- topic.handle message
43
- end
44
+ def subscribe
45
+ @push_topics.each do |topic|
46
+ client.subscribe topic.name, replay: Configuration.instance.replay_adapter do |message|
47
+ Log.info "Message #{message.dig('event', 'replayId')} received from topic #{topic.name}"
48
+ topic.handle message
44
49
  end
45
50
  end
46
51
  end
@@ -1,3 +1,3 @@
1
1
  module SalesforceStreamer
2
- VERSION = '2.2.0'.freeze
2
+ VERSION = '2.3.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.2.0
4
+ version: 2.3.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-11-11 00:00:00.000000000 Z
12
+ date: 2020-11-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dry-initializer