message_bus 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of message_bus might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce14b8278c7817109ad5bbfaa4074aea98c16f48
4
- data.tar.gz: 13ebcc84003602fd4472aa962e1c213492856c2f
3
+ metadata.gz: 80297cfac62f4fc79e8d16a425762576757aab5d
4
+ data.tar.gz: be8b74aed2b678c858de6a2941f74bcbaad455c2
5
5
  SHA512:
6
- metadata.gz: 2ed7d150b899fdd94f19696dff09e333ac4ce51cc9b4438c57514cc671f0ac4cb38092cf8a1202d8025e7c3e506a1f7d5869831ab072a5edb6ae94797238a24e
7
- data.tar.gz: 5604f489628fb9885bec1c2dc5eac3cb209e077dcbc6677745a8c3a4a8dd43955692272675fc807e29f309dec88edb52689df98cbb7dd60774a213cd16db1d78
6
+ metadata.gz: 32fafd6d57c0176cc356724246909d430753428b375449b8c12a181dd8b2f50ab51404a6fd0c02a089cc7fbe2bf90e6071df6b5a24324fa0b0430e3c6f163460
7
+ data.tar.gz: e977e8bc61bdd4c74be64fe755ad413e036ae96fc149ccb26cbae05fb1bca53dcb45cf82b0ea6ae5e77e13ee3e3fc7a87a5068d6cbe98e5994f440c9668e43ca
data/CHANGELOG CHANGED
@@ -1,3 +1,14 @@
1
+ 25-08-2016
2
+
3
+ - Version 2.0.2
4
+ - Feature: Add on_middleware_error callback for remapping middleware errors to HTTP results
5
+
6
+
7
+ 25-07-2016
8
+
9
+ - Feature: Add JavaScript MessageBus.status() function
10
+
11
+
1
12
  21-06-2016
2
13
 
3
14
  - Version 2.0.1
data/README.md CHANGED
@@ -83,6 +83,12 @@ MessageBus.configure(group_ids_lookup: proc do |env|
83
83
  # can be nil or []
84
84
  end)
85
85
 
86
+ MessageBus.configure(on_middleware_error: proc do |env, e|
87
+ # If you wish to add special handling based on error
88
+ # return a rack result array: [status, headers, body]
89
+ # If you just want to pass it on return nil
90
+ end)
91
+
86
92
  # example of message bus to set user_ids from an initializer in Rails and Devise:
87
93
  # config/inializers/message_bus.rb
88
94
  MessageBus.user_id_lookup do |env|
@@ -212,7 +218,9 @@ headers|{}|Extra headers to be include with request. Properties and values of o
212
218
 
213
219
  `MessageBus.start()` : Must be called to startup the MessageBus poller
214
220
 
215
- `MessageBus.subscribe(channel,func,lastId)` : Subscribe to a channel, optionally you may specify the id of the last message you received in the channel.
221
+ `MessageBus.status()` : Return status (started, paused, stopped)
222
+
223
+ `MessageBus.subscribe(channel,func,lastId)` : Subscribe to a channel, optionally you may specify the id of the last message you received in the channel. The callback accepts three arguments: `func(payload, globalId, messageId)`. You may save globalId or messageId of received messages and use then at a later time when client needs to subscribe, receiving the backlog just after that Id.
216
224
 
217
225
  `MessageBus.unsubscribe(channel,func)` : Unsubscribe callback from a particular channel
218
226
 
@@ -299,7 +307,7 @@ For more information see [Passenger documentation](https://www.phusionpassenger.
299
307
  #### Puma
300
308
  ```ruby
301
309
  # path/to/your/config/puma.rb
302
- require 'message_bus'
310
+ require 'message_bus' # omit this line for Rails 5
303
311
  on_worker_boot do
304
312
  MessageBus.after_fork
305
313
  end
@@ -73,7 +73,7 @@
73
73
  if (callback.channel === message.channel) {
74
74
  callback.last_id = message.message_id;
75
75
  try {
76
- callback.func(message.data);
76
+ callback.func(message.data, message.global_id, message.message_id);
77
77
  }
78
78
  catch(e){
79
79
  if(console.log) {
@@ -352,6 +352,18 @@
352
352
  poll();
353
353
  },
354
354
 
355
+ "status": function() {
356
+ if (paused) {
357
+ return "paused";
358
+ } else if (started) {
359
+ return "started";
360
+ } else if (stopped) {
361
+ return "stopped";
362
+ } else {
363
+ throw "Cannot determine current status";
364
+ }
365
+ },
366
+
355
367
  // Subscribe to a channel
356
368
  subscribe: function(channel, func, lastId) {
357
369
 
data/lib/message_bus.rb CHANGED
@@ -154,6 +154,11 @@ module MessageBus::Implementation
154
154
  @config[:is_admin_lookup]
155
155
  end
156
156
 
157
+ def on_middleware_error(&blk)
158
+ configure(on_middleware_error: blk) if blk
159
+ @config[:on_middleware_error]
160
+ end
161
+
157
162
  def extra_response_headers_lookup(&blk)
158
163
  configure(extra_response_headers_lookup: blk) if blk
159
164
  @config[:extra_response_headers_lookup]
@@ -181,6 +181,13 @@ class MessageBus::Rack::Middleware
181
181
  else
182
182
  [200, headers, ["[]"]]
183
183
  end
184
+
185
+ rescue => e
186
+ if @bus.on_middleware_error && result=@bus.on_middleware_error.call(env, e)
187
+ result
188
+ else
189
+ raise
190
+ end
184
191
  end
185
192
 
186
193
  def close_db_connection!
@@ -1,3 +1,3 @@
1
1
  module MessageBus
2
- VERSION = "2.0.1"
2
+ VERSION = "2.0.2"
3
3
  end
@@ -20,6 +20,16 @@ describe("Messagebus", function() {
20
20
  });
21
21
  });
22
22
 
23
+ it('returns status', function(done){
24
+ MessageBus.pause();
25
+ expect(MessageBus.status()).toMatch("paused");
26
+ MessageBus.resume();
27
+ expect(MessageBus.status()).toMatch("started");
28
+ MessageBus.stop();
29
+ expect(MessageBus.status()).toMatch("stopped");
30
+ done();
31
+ });
32
+
23
33
  it('stores messages when paused, then delivers them when resumed', function(done){
24
34
  MessageBus.pause()
25
35
  spyOn(this.MockedXMLHttpRequest.prototype, 'send').and.callThrough();
@@ -309,6 +309,28 @@ describe MessageBus::Rack::Middleware do
309
309
  JSON.parse(last_response.body).first["data"].must_equal({'json' => true})
310
310
  end
311
311
 
312
+ describe "on_middleware_error handling" do
313
+ it "allows error handling of middleware failures" do
314
+
315
+ @bus.on_middleware_error do |env, err|
316
+ if ArgumentError === err
317
+ [407,{},[]]
318
+ end
319
+ end
320
+
321
+ @bus.group_ids_lookup do |env|
322
+ raise ArgumentError
323
+ end
324
+
325
+ post( "/message-bus/1234",
326
+ JSON.generate({'/foo' => 1}),
327
+ { "CONTENT_TYPE" => "application/json" })
328
+
329
+ last_response.status.must_equal 407
330
+
331
+ end
332
+ end
333
+
312
334
  describe "messagebus.channels env support" do
313
335
  let(:extra_middleware) do
314
336
  Class.new do
@@ -73,7 +73,7 @@
73
73
  if (callback.channel === message.channel) {
74
74
  callback.last_id = message.message_id;
75
75
  try {
76
- callback.func(message.data);
76
+ callback.func(message.data, message.global_id, message.message_id);
77
77
  }
78
78
  catch(e){
79
79
  if(console.log) {
@@ -352,6 +352,18 @@
352
352
  poll();
353
353
  },
354
354
 
355
+ "status": function() {
356
+ if (paused) {
357
+ return "paused";
358
+ } else if (started) {
359
+ return "started";
360
+ } else if (stopped) {
361
+ return "stopped";
362
+ } else {
363
+ throw "Cannot determine current status";
364
+ }
365
+ },
366
+
355
367
  // Subscribe to a channel
356
368
  subscribe: function(channel, func, lastId) {
357
369
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: message_bus
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-21 00:00:00.000000000 Z
11
+ date: 2016-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack