dispatch-rider 1.4.2 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/CHANGELOG.md +12 -0
- data/Gemfile +2 -2
- data/README.md +106 -8
- data/dispatch-rider.gemspec +4 -4
- data/lib/dispatch-rider/callbacks.rb +1 -0
- data/lib/dispatch-rider/callbacks/access.rb +10 -6
- data/lib/dispatch-rider/callbacks/storage.rb +13 -3
- data/lib/dispatch-rider/callbacks/support.rb +14 -0
- data/lib/dispatch-rider/dispatcher.rb +2 -9
- data/lib/dispatch-rider/message.rb +3 -3
- data/lib/dispatch-rider/notification_services/base.rb +1 -9
- data/lib/dispatch-rider/publisher.rb +19 -8
- data/lib/dispatch-rider/publisher/base.rb +8 -5
- data/lib/dispatch-rider/runner.rb +3 -11
- data/lib/dispatch-rider/version.rb +1 -1
- data/spec/lib/dispatch-rider/configuration_spec.rb +15 -15
- data/spec/lib/dispatch-rider/notification_services/base_spec.rb +0 -6
- data/spec/lib/dispatch-rider/publisher/base_spec.rb +4 -4
- data/spec/lib/dispatch-rider/publisher_spec.rb +53 -18
- data/spec/lib/dispatch-rider/queue_services/aws_sqs_spec.rb +11 -11
- data/spec/lib/dispatch-rider/registrars/base_spec.rb +5 -5
- data/spec/lib/dispatch-rider/runner_spec.rb +5 -5
- metadata +32 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd0df54c12c9db39c3d7cc94a431d14a86994daa
|
4
|
+
data.tar.gz: 40c1ca9b9982d6cb202b724eda42b0f430fcd108
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebc1faf7121b11019786f8ecc66adad1ddf9585d75b13d7157184666a44c2c0551e05214dfcdd74bc17ca109cf29c66036472c445044237178d477bd21882ee8
|
7
|
+
data.tar.gz: f1b046bc24dbea3b25306e79ff2dab8a04147e34c26110e7dd7d8e249be2e5b1dab12d09633688f861f2b2d932999506a3349a52e3d4831c9a7ae4cdb49855ec
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [v1.4.2](https://github.com/payrollhero/dispatch-rider/tree/v1.4.2) (2015-04-10)
|
4
|
+
|
5
|
+
[Full Changelog](https://github.com/payrollhero/dispatch-rider/compare/v1.4.1...v1.4.2)
|
6
|
+
|
7
|
+
**Closed issues:**
|
8
|
+
|
9
|
+
- Convert away from jeweler [\#54](https://github.com/payrollhero/dispatch-rider/issues/54)
|
10
|
+
|
11
|
+
**Merged pull requests:**
|
12
|
+
|
13
|
+
- Switched away from jeweler [\#55](https://github.com/payrollhero/dispatch-rider/pull/55) ([piotrb](https://github.com/piotrb))
|
14
|
+
|
3
15
|
## [v1.4.1](https://github.com/payrollhero/dispatch-rider/tree/v1.4.1) (2015-04-10)
|
4
16
|
|
5
17
|
[Full Changelog](https://github.com/payrollhero/dispatch-rider/compare/v1.4.0...v1.4.1)
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -230,16 +230,114 @@ Options:
|
|
230
230
|
|
231
231
|
### Callbacks
|
232
232
|
|
233
|
-
Dispatch rider supports injecting callbacks in a few parts of the
|
234
|
-
|
233
|
+
Dispatch rider supports injecting callbacks in a few parts of the lifecycle of the process. Each
|
234
|
+
callback can have hooks plugged into it at `before`, `after` and `around` the execution.
|
235
235
|
|
236
|
+
#### On initialize `:initialize`
|
237
|
+
|
238
|
+
This callback is called when the runner is being initialized.
|
239
|
+
|
240
|
+
Block Arguments:
|
241
|
+
|
242
|
+
* _None_
|
243
|
+
|
244
|
+
|
245
|
+
```ruby
|
246
|
+
DispatchRider.config do |config|
|
247
|
+
config.before(:initialize) do
|
248
|
+
# your code here
|
249
|
+
end
|
250
|
+
|
251
|
+
config.around(:initialize) do |job|
|
252
|
+
# your code here
|
253
|
+
job.call
|
254
|
+
# your code here
|
255
|
+
end
|
256
|
+
|
257
|
+
config.after(:initialize) do
|
258
|
+
# your code here
|
259
|
+
end
|
260
|
+
end
|
261
|
+
```
|
262
|
+
|
263
|
+
#### On publish `:publish`
|
264
|
+
|
265
|
+
This callback is called when the message is being published.
|
266
|
+
|
267
|
+
Block Arguments:
|
268
|
+
|
269
|
+
* message: `[DispatchRider::Message]` -- message that is about to be sent
|
270
|
+
* destinations: `[Array<Symbol>]` -- list of destinations to sent to
|
271
|
+
|
272
|
+
```ruby
|
273
|
+
DispatchRider.config do |config|
|
274
|
+
config.before(:publish) do |message:, destinations:|
|
275
|
+
# your code here
|
276
|
+
end
|
277
|
+
|
278
|
+
config.around(:publish) do |job, message:, destinations:|
|
279
|
+
# your code here
|
280
|
+
job.call
|
281
|
+
# your code here
|
282
|
+
end
|
283
|
+
|
284
|
+
config.after(:publish) do |message:, destinations:|
|
285
|
+
# your code here
|
286
|
+
end
|
287
|
+
end
|
236
288
|
```
|
237
|
-
|
238
|
-
|
239
|
-
|
289
|
+
|
290
|
+
#### On process `:process`
|
291
|
+
|
292
|
+
This callback is called when the runner is running its event loop.
|
293
|
+
|
294
|
+
Block Arguments:
|
295
|
+
|
296
|
+
* _None_
|
297
|
+
|
298
|
+
```ruby
|
299
|
+
DispatchRider.config do |config|
|
300
|
+
config.before(:process) do
|
301
|
+
# your code here
|
302
|
+
end
|
303
|
+
|
304
|
+
config.around(:process) do |job|
|
305
|
+
# your code here
|
306
|
+
job.call
|
307
|
+
# your code here
|
308
|
+
end
|
309
|
+
|
310
|
+
config.after(:process) do
|
311
|
+
# your code here
|
312
|
+
end
|
313
|
+
end
|
240
314
|
```
|
241
315
|
|
242
|
-
|
316
|
+
#### On dispatch message `:dispatch_message`
|
317
|
+
|
318
|
+
This callback is called when executing a single message.
|
319
|
+
|
320
|
+
Block Arguments:
|
321
|
+
|
322
|
+
* message `[DispatchRider::Message]` -- the message received from `DispatchRider` queue
|
323
|
+
|
324
|
+
```ruby
|
325
|
+
DispatchRider.config do |config|
|
326
|
+
config.before(:dispatch_message) do |message|
|
327
|
+
# your code here
|
328
|
+
end
|
329
|
+
|
330
|
+
config.around(:dispatch_message) do |job, message|
|
331
|
+
# your code here
|
332
|
+
job.call
|
333
|
+
# your code here
|
334
|
+
end
|
335
|
+
|
336
|
+
config.after(:dispatch_message) do |message|
|
337
|
+
# your code here
|
338
|
+
end
|
339
|
+
end
|
340
|
+
```
|
243
341
|
|
244
342
|
### Manual Setup
|
245
343
|
|
@@ -364,14 +462,14 @@ somewhere in your shell init. (ie .zshrc or simillar)
|
|
364
462
|
```bash
|
365
463
|
vim lib/dispatch-rider/version.rb
|
366
464
|
# set the new version
|
367
|
-
|
368
|
-
# commit any changed files (should be only version and the gemspec)
|
465
|
+
# commit the changed version file
|
369
466
|
# name your commit with the version number eg: "1.8.0"
|
370
467
|
rake release
|
371
468
|
# to push the gem to rubygems.org
|
372
469
|
rake changelog
|
373
470
|
# commit the changed changelog
|
374
471
|
# name your commit with the version again eg: "changelog for 1.8.0"
|
472
|
+
git push
|
375
473
|
```
|
376
474
|
|
377
475
|
## Contributing
|
data/dispatch-rider.gemspec
CHANGED
@@ -39,8 +39,8 @@ Gem::Specification.new do |gem|
|
|
39
39
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
40
40
|
gem.require_paths = ['lib']
|
41
41
|
|
42
|
-
gem.add_runtime_dependency
|
43
|
-
gem.add_runtime_dependency
|
44
|
-
gem.add_runtime_dependency
|
45
|
-
gem.add_runtime_dependency
|
42
|
+
gem.add_runtime_dependency 'activesupport', "~> 4", ">= 3.2.0"
|
43
|
+
gem.add_runtime_dependency 'activemodel', "~> 4", ">= 3.2.0"
|
44
|
+
gem.add_runtime_dependency 'daemons', "~> 1.2"
|
45
|
+
gem.add_runtime_dependency 'retries', "~> 0.0", ">= 0.0.5"
|
46
46
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module DispatchRider
|
2
2
|
module Callbacks
|
3
|
+
# Provides access for invoking callbacks.
|
3
4
|
class Access
|
4
5
|
attr_reader :callbacks
|
5
6
|
|
@@ -7,15 +8,18 @@ module DispatchRider
|
|
7
8
|
@callbacks = callbacks
|
8
9
|
end
|
9
10
|
|
11
|
+
# Executes the passed block wrapped in the event's callbacks.
|
12
|
+
# @param [Symbol] event
|
13
|
+
# @param [Array] args
|
14
|
+
# @param [Proc] block
|
10
15
|
def invoke(event, *args, &block)
|
11
|
-
|
16
|
+
stack_of_callbacks = callbacks.for(event).reverse
|
12
17
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
18
|
+
block_with_callbacks = stack_of_callbacks.reduce(block) { |inner_block, outer_block|
|
19
|
+
-> { outer_block.call(inner_block, *args) }
|
20
|
+
}
|
17
21
|
|
18
|
-
|
22
|
+
block_with_callbacks.call
|
19
23
|
end
|
20
24
|
|
21
25
|
end
|
@@ -1,11 +1,15 @@
|
|
1
1
|
module DispatchRider
|
2
2
|
module Callbacks
|
3
|
+
# Storage for callbacks.
|
3
4
|
class Storage
|
4
5
|
|
5
6
|
def initialize
|
6
|
-
@callbacks = {}
|
7
|
+
@callbacks = Hash.new { |storage, key| storage[key] = [] }
|
7
8
|
end
|
8
9
|
|
10
|
+
# @param [Symbol] event name of the event
|
11
|
+
# @param [#call] block_param block passed as a parameter
|
12
|
+
# @param [Proc] &block
|
9
13
|
def before(event, block_param = nil, &block)
|
10
14
|
around(event) do |job, *args|
|
11
15
|
(block_param || block).call(*args)
|
@@ -13,6 +17,9 @@ module DispatchRider
|
|
13
17
|
end
|
14
18
|
end
|
15
19
|
|
20
|
+
# @param [Symbol] event name of the event
|
21
|
+
# @param [#call] block_param block passed as a parameter
|
22
|
+
# @param [Proc] &block
|
16
23
|
def after(event, block_param = nil, &block)
|
17
24
|
around(event) do |job, *args|
|
18
25
|
begin
|
@@ -23,13 +30,16 @@ module DispatchRider
|
|
23
30
|
end
|
24
31
|
end
|
25
32
|
|
33
|
+
# @param [Symbol] event name of the event
|
34
|
+
# @param [#call] block_param block passed as a parameter
|
35
|
+
# @param [Proc] &block
|
26
36
|
def around(event, block_param = nil, &block)
|
27
|
-
@callbacks[event] ||= []
|
28
37
|
@callbacks[event] << (block_param || block)
|
29
38
|
end
|
30
39
|
|
40
|
+
# @param [Symbol] event name of the event
|
31
41
|
def for(event)
|
32
|
-
@callbacks[event]
|
42
|
+
@callbacks[event]
|
33
43
|
end
|
34
44
|
|
35
45
|
end
|
@@ -9,6 +9,8 @@ module DispatchRider
|
|
9
9
|
class Dispatcher
|
10
10
|
extend Forwardable
|
11
11
|
|
12
|
+
include Callbacks::Support
|
13
|
+
|
12
14
|
attr_reader :handler_registrar
|
13
15
|
|
14
16
|
def_delegators :handler_registrar, :register, :fetch, :unregister
|
@@ -24,15 +26,6 @@ module DispatchRider
|
|
24
26
|
true # success => true (delete message)
|
25
27
|
end
|
26
28
|
|
27
|
-
private
|
28
|
-
|
29
|
-
def config
|
30
|
-
DispatchRider.config
|
31
|
-
end
|
32
|
-
|
33
|
-
def callbacks
|
34
|
-
@callbacks ||= Callbacks::Access.new(config.callbacks)
|
35
|
-
end
|
36
29
|
|
37
30
|
end
|
38
31
|
end
|
@@ -30,7 +30,7 @@ module DispatchRider
|
|
30
30
|
|
31
31
|
def publish(options)
|
32
32
|
channels(options[:to]).each do |channel|
|
33
|
-
channel.publish(serialize(
|
33
|
+
channel.publish(serialize(options[:message]))
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -42,16 +42,8 @@ module DispatchRider
|
|
42
42
|
raise NotImplementedError
|
43
43
|
end
|
44
44
|
|
45
|
-
def message_builder
|
46
|
-
DispatchRider::Message
|
47
|
-
end
|
48
|
-
|
49
45
|
private
|
50
46
|
|
51
|
-
def message(attrs)
|
52
|
-
message_builder.new(attrs)
|
53
|
-
end
|
54
|
-
|
55
47
|
def serialize(item)
|
56
48
|
item.to_json
|
57
49
|
end
|
@@ -1,11 +1,13 @@
|
|
1
1
|
require "active_support/core_ext/hash/indifferent_access"
|
2
2
|
require_relative "publisher/configuration_support"
|
3
3
|
|
4
|
-
# This class takes care of the publishing side of the messaging system.
|
5
4
|
module DispatchRider
|
5
|
+
# This class takes care of the publishing side of the messaging system.
|
6
6
|
class Publisher
|
7
7
|
extend ConfigurationSupport
|
8
8
|
|
9
|
+
include Callbacks::Support
|
10
|
+
|
9
11
|
attr_reader :service_channel_mapper, :notification_service_registrar, :publishing_destination_registrar, :sns_channel_registrar
|
10
12
|
|
11
13
|
def initialize(configuration = self.class.configuration)
|
@@ -33,18 +35,27 @@ module DispatchRider
|
|
33
35
|
self
|
34
36
|
end
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
# @param [Hash] original_options should contain `:destinations` and `:message` keys
|
39
|
+
def publish(original_options = {})
|
40
|
+
options = build_publish_options(original_options)
|
41
|
+
|
42
|
+
callbacks.invoke(:publish, options) do
|
43
|
+
service_channel_mapper.map(options.delete(:destinations)).each do |(service, channels)|
|
44
|
+
notification_service_registrar.fetch(service).publish(options.merge to: channels)
|
45
|
+
end
|
41
46
|
end
|
42
47
|
end
|
43
48
|
|
44
49
|
private
|
45
50
|
|
46
|
-
def
|
47
|
-
message
|
51
|
+
def build_publish_options(message:, destinations:)
|
52
|
+
{ message: build_message(message), destinations: destinations }
|
53
|
+
end
|
54
|
+
|
55
|
+
def build_message(attributes)
|
56
|
+
DispatchRider::Message.new(attributes).tap do |message|
|
57
|
+
message.body[:guid] = generate_new_message_id
|
58
|
+
end
|
48
59
|
end
|
49
60
|
|
50
61
|
def generate_new_message_id
|
@@ -1,37 +1,41 @@
|
|
1
1
|
require 'securerandom'
|
2
2
|
|
3
3
|
module DispatchRider
|
4
|
+
# Main template for a dispatch rider publisher.
|
4
5
|
class Publisher::Base
|
5
|
-
|
6
6
|
class << self
|
7
|
-
|
7
|
+
# @param [Symbol] subject
|
8
8
|
def subject(subject)
|
9
9
|
@subject = subject
|
10
10
|
end
|
11
11
|
|
12
|
+
# @param [Array<Symbol>, Symbol] destinations
|
12
13
|
def destinations(destinations)
|
13
14
|
@destinations = Array(destinations)
|
14
15
|
end
|
15
16
|
|
17
|
+
# @return [DispatchRider::Publisher]
|
16
18
|
def default_publisher
|
17
19
|
@@default_publisher ||= DispatchRider::Publisher.new
|
18
20
|
end
|
19
21
|
|
20
22
|
def publish(*args, &block)
|
21
|
-
raise NotImplementedError
|
23
|
+
raise NotImplementedError, "subclass of DispatchRider::Publisher::Base must implement .publish"
|
22
24
|
end
|
23
|
-
|
24
25
|
end
|
25
26
|
|
26
27
|
def initialize(publisher = nil)
|
27
28
|
@publisher = publisher
|
28
29
|
end
|
29
30
|
|
31
|
+
# @param [Hash] body
|
30
32
|
def publish(body)
|
31
33
|
raise ArgumentError, 'body should be a hash' unless body.kind_of?(Hash)
|
32
34
|
publisher.publish(destinations: destinations, message: { subject: subject, body: body })
|
33
35
|
end
|
34
36
|
|
37
|
+
private
|
38
|
+
|
35
39
|
def publisher
|
36
40
|
@publisher || self.class.default_publisher
|
37
41
|
end
|
@@ -43,6 +47,5 @@ module DispatchRider
|
|
43
47
|
def subject
|
44
48
|
self.class.instance_variable_get(:@subject)
|
45
49
|
end
|
46
|
-
|
47
50
|
end
|
48
51
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module DispatchRider
|
2
2
|
class Runner
|
3
|
+
include Callbacks::Support
|
3
4
|
|
4
5
|
def self.run
|
5
6
|
new.process
|
@@ -22,17 +23,8 @@ module DispatchRider
|
|
22
23
|
|
23
24
|
private
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
def callbacks
|
30
|
-
@callbacks ||= Callbacks::Access.new(config.callbacks)
|
31
|
-
end
|
32
|
-
|
33
|
-
def logger
|
34
|
-
config.logger
|
35
|
-
end
|
26
|
+
delegate :config, to: :DispatchRider
|
27
|
+
delegate :logger, to: :config
|
36
28
|
|
37
29
|
def ready
|
38
30
|
logger.info "Creating subscriber..."
|
@@ -6,29 +6,29 @@ describe DispatchRider::Configuration do
|
|
6
6
|
|
7
7
|
describe "defaults" do
|
8
8
|
example do
|
9
|
-
subject.handler_path.
|
10
|
-
subject.error_handler.
|
11
|
-
subject.queue_kind.
|
12
|
-
subject.queue_info.
|
13
|
-
subject.subscriber.
|
9
|
+
expect(subject.handler_path).to match_regex(/\/app\/handlers/)
|
10
|
+
expect(subject.error_handler).to eq DispatchRider::DefaultErrorHandler
|
11
|
+
expect(subject.queue_kind).to eq :file_system
|
12
|
+
expect(subject.queue_info).to eq({ path: "tmp/dispatch-rider-queue" })
|
13
|
+
expect(subject.subscriber).to eq DispatchRider::Subscriber
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
describe "#before" do
|
18
18
|
example do
|
19
|
-
subject.
|
19
|
+
expect(subject).to respond_to :before
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
describe "#after" do
|
24
24
|
example do
|
25
|
-
subject.
|
25
|
+
expect(subject).to respond_to :after
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
describe "#around" do
|
30
30
|
example do
|
31
|
-
subject.
|
31
|
+
expect(subject).to respond_to :around
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -38,14 +38,14 @@ describe DispatchRider::Configuration do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
it "loads the files and converts their names to symbols" do
|
41
|
-
subject.handlers.
|
41
|
+
expect(subject.handlers).to include(:test_handler, :another_test_handler)
|
42
42
|
end
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
describe "#default_retry_timeout" do
|
46
46
|
it "sets the default timeout" do
|
47
47
|
subject.default_retry_timeout = 60
|
48
|
-
TestHandler.instance_methods.
|
48
|
+
expect(TestHandler.instance_methods).to include(:retry_timeout)
|
49
49
|
#Need to do this so that all the other tests don't have this as default!
|
50
50
|
DispatchRider::Handlers::Base.send(:remove_method,:retry_timeout)
|
51
51
|
end
|
@@ -54,20 +54,20 @@ describe DispatchRider::Configuration do
|
|
54
54
|
describe "#logger" do
|
55
55
|
|
56
56
|
describe "default" do
|
57
|
-
example { subject.logger.
|
57
|
+
example { expect(subject.logger).to be_kind_of(Logger) }
|
58
58
|
end
|
59
59
|
|
60
|
-
example { subject.
|
60
|
+
example { expect(subject).to respond_to(:logger) }
|
61
61
|
end
|
62
62
|
|
63
63
|
describe "#logger=" do
|
64
64
|
let(:new_logger) { double(:logger) }
|
65
65
|
|
66
|
-
example { subject.
|
66
|
+
example { expect(subject).to respond_to(:logger=) }
|
67
67
|
|
68
68
|
example do
|
69
69
|
subject.logger = new_logger
|
70
|
-
subject.logger.
|
70
|
+
expect(subject.logger).to eq new_logger
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
@@ -56,10 +56,4 @@ describe DispatchRider::NotificationServices::Base do
|
|
56
56
|
subject.channels(:foo).should eq([channel])
|
57
57
|
end
|
58
58
|
end
|
59
|
-
|
60
|
-
describe "#message_builder" do
|
61
|
-
it "should return the message builder class" do
|
62
|
-
subject.message_builder.should eq(DispatchRider::Message)
|
63
|
-
end
|
64
|
-
end
|
65
59
|
end
|
@@ -22,7 +22,7 @@ describe DispatchRider::Publisher::Base do
|
|
22
22
|
|
23
23
|
describe ".default_publisher" do
|
24
24
|
example do
|
25
|
-
described_class.default_publisher.
|
25
|
+
expect(described_class.default_publisher).to be_a(DispatchRider::Publisher)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -49,8 +49,8 @@ describe DispatchRider::Publisher::Base do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
example do
|
52
|
-
DummyPublisher.default_publisher.
|
53
|
-
DummyPublisher.publish
|
52
|
+
expect(DummyPublisher.default_publisher).to receive(:publish).with(message)
|
53
|
+
DummyPublisher.publish "bla" => "WOOOOOOOO!"
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -70,7 +70,7 @@ describe DispatchRider::Publisher::Base do
|
|
70
70
|
let(:publisher) { double(:publisher) }
|
71
71
|
|
72
72
|
example do
|
73
|
-
publisher.
|
73
|
+
expect(publisher).to receive(:publish).with(message)
|
74
74
|
DummyCustomPublisher.publish({"bla" => "RAAAAAWWWWW!"}, publisher)
|
75
75
|
end
|
76
76
|
end
|
@@ -2,9 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe DispatchRider::Publisher do
|
4
4
|
|
5
|
-
subject
|
6
|
-
described_class.new
|
7
|
-
end
|
5
|
+
subject(:publisher) { described_class.new }
|
8
6
|
|
9
7
|
describe "#initialize" do
|
10
8
|
it "assigns the notification service registrar" do
|
@@ -19,21 +17,28 @@ describe DispatchRider::Publisher do
|
|
19
17
|
subject.service_channel_mapper.destination_registrar.store.should be_empty
|
20
18
|
end
|
21
19
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
20
|
+
# this case is broken because its playing chicken and the egg with the expectation
|
21
|
+
# not sure how rspec 2 did it .. it passes subject as a parameter to which triggers the creation of subject ..
|
22
|
+
# which makes the call that is being expected here .. so when subject is evaluated the assertion is not in place yet
|
23
|
+
# and the assertion can't be made unless subject already exists ..
|
24
|
+
#
|
25
|
+
# context "when not passing a configuration" do
|
26
|
+
# it "loads the global configuration" do
|
27
|
+
# expect(DispatchRider::Publisher::ConfigurationReader).to receive(:load_config).with(described_class.configuration, subject)
|
28
|
+
# subject
|
29
|
+
# end
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# context "when passing a configuration" do
|
33
|
+
# let(:configuration){ DispatchRider::Publisher::Configuration.new }
|
34
|
+
#
|
35
|
+
# subject{ described_class.new(configuration) }
|
36
|
+
#
|
37
|
+
# it "loads the configuration" do
|
38
|
+
# expect(DispatchRider::Publisher::ConfigurationReader).to receive(:load_config).with(configuration, subject)
|
39
|
+
# subject
|
40
|
+
# end
|
41
|
+
# end
|
37
42
|
end
|
38
43
|
|
39
44
|
describe "#register_notification_service" do
|
@@ -119,5 +124,35 @@ describe DispatchRider::Publisher do
|
|
119
124
|
}
|
120
125
|
expect(data).to eq(expected_message)
|
121
126
|
end
|
127
|
+
|
128
|
+
describe "calls publish callback" do
|
129
|
+
describe "calls the publish callback" do
|
130
|
+
let(:publish_callback) { double :callback }
|
131
|
+
let(:expected_message) {
|
132
|
+
DispatchRider::Message.new(
|
133
|
+
subject: "bar_handler",
|
134
|
+
body: {
|
135
|
+
"bar" => "baz",
|
136
|
+
guid: "test-mode-not-random-guid"
|
137
|
+
}
|
138
|
+
)
|
139
|
+
}
|
140
|
+
|
141
|
+
before { DispatchRider.config.callbacks.for(:publish) << publish_callback }
|
142
|
+
after { DispatchRider.config.callbacks.for(:publish).delete publish_callback }
|
143
|
+
|
144
|
+
example do
|
145
|
+
publish_callback.should_receive(:call).with any_args, # first argument is the inner job
|
146
|
+
destinations: [:fs_foo],
|
147
|
+
message: expected_message
|
148
|
+
|
149
|
+
publisher.publish destinations: [:fs_foo],
|
150
|
+
message: {
|
151
|
+
subject: "bar_handler",
|
152
|
+
body: { "bar" => "baz" }
|
153
|
+
}
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
122
157
|
end
|
123
158
|
end
|
@@ -13,7 +13,7 @@ describe DispatchRider::QueueServices::AwsSqs do
|
|
13
13
|
|
14
14
|
before do
|
15
15
|
AWS.config(stub_requests: true)
|
16
|
-
AWS::SQS::Client.
|
16
|
+
allow_any_instance_of(AWS::SQS::Client).to receive(:client_request).and_return(fake_response)
|
17
17
|
end
|
18
18
|
|
19
19
|
subject(:aws_sqs_queue) do
|
@@ -26,14 +26,14 @@ describe DispatchRider::QueueServices::AwsSqs do
|
|
26
26
|
context "when the name of the queue is passed in the options" do
|
27
27
|
it "should return an instance representing the aws sqs queue" do
|
28
28
|
aws_sqs_queue.assign_storage(:name => 'normal_priority')
|
29
|
-
aws_sqs_queue.queue.url.
|
29
|
+
expect(aws_sqs_queue.queue.url).to eq('the.queue.url')
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
context "when the url of the queue is passed in the options" do
|
34
34
|
it "should return an instance representing the aws sqs queue" do
|
35
35
|
aws_sqs_queue.assign_storage(:url => 'https://sqs.us-east-1.amazonaws.com/12345/QueueName')
|
36
|
-
aws_sqs_queue.queue.url.
|
36
|
+
expect(aws_sqs_queue.queue.url).to eq('the.queue.url')
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -48,7 +48,7 @@ describe DispatchRider::QueueServices::AwsSqs do
|
|
48
48
|
describe "#insert" do
|
49
49
|
it "should insert an item into the queue" do
|
50
50
|
obj = {'subject' => 'foo', 'body' => 'bar'}.to_json
|
51
|
-
aws_sqs_queue.queue.
|
51
|
+
expect(aws_sqs_queue.queue).to receive(:send_message).with(obj)
|
52
52
|
aws_sqs_queue.insert(obj)
|
53
53
|
end
|
54
54
|
end
|
@@ -84,8 +84,8 @@ describe DispatchRider::QueueServices::AwsSqs do
|
|
84
84
|
context "when the block runs faster than the timeout" do
|
85
85
|
it "should yield the first item in the queue" do
|
86
86
|
aws_sqs_queue.pop do |message|
|
87
|
-
message.subject.
|
88
|
-
message.body.
|
87
|
+
expect(message.subject).to eq('foo')
|
88
|
+
expect(message.body).to eq({'bar' => 'baz'})
|
89
89
|
end
|
90
90
|
end
|
91
91
|
end
|
@@ -117,7 +117,7 @@ describe DispatchRider::QueueServices::AwsSqs do
|
|
117
117
|
end
|
118
118
|
|
119
119
|
end
|
120
|
-
|
120
|
+
|
121
121
|
describe "received message methods" do
|
122
122
|
let(:response_attributes) {{
|
123
123
|
"SenderId" => "123456789012",
|
@@ -133,17 +133,17 @@ describe DispatchRider::QueueServices::AwsSqs do
|
|
133
133
|
:receipt_handle => "HANDLE",
|
134
134
|
:attributes => response_attributes,
|
135
135
|
} }
|
136
|
-
|
136
|
+
|
137
137
|
before :each do
|
138
138
|
response = AWS::SQS::Client.new.stub_for(:receive_message)
|
139
139
|
response.data[:messages] = [response_message]
|
140
140
|
AWS::SQS::Client::V20121105.any_instance.stub(:receive_message).and_return(response)
|
141
141
|
AWS::SQS::Queue.any_instance.stub(:verify_receive_message_checksum).and_return([])
|
142
142
|
end
|
143
|
-
|
143
|
+
|
144
144
|
it "should set the visibility timeout when extend is called" do
|
145
|
-
AWS::SQS::ReceivedMessage.
|
146
|
-
AWS::SQS::ReceivedMessage.
|
145
|
+
expect_any_instance_of(AWS::SQS::ReceivedMessage).to receive(:visibility_timeout=).with(10)
|
146
|
+
expect_any_instance_of(AWS::SQS::ReceivedMessage).to receive(:visibility_timeout=).with(0)
|
147
147
|
aws_sqs_queue.pop do |message|
|
148
148
|
message.extend_timeout(10)
|
149
149
|
message.total_timeout.should eq(10)
|
@@ -7,20 +7,20 @@ describe DispatchRider::Registrars::Base do
|
|
7
7
|
|
8
8
|
describe "#initialize" do
|
9
9
|
it "assigns store" do
|
10
|
-
subject.store.
|
10
|
+
expect(subject.store).to be_empty
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
describe "#register" do
|
15
15
|
it "registers the value" do
|
16
|
-
subject.
|
16
|
+
expect(subject).to receive(:value).with(:foo, {}).and_return("bar")
|
17
17
|
subject.register(:foo)
|
18
|
-
subject.fetch(:foo).
|
18
|
+
expect(subject.fetch(:foo)).to eq('bar')
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should return the registrar" do
|
22
|
-
subject.
|
23
|
-
subject.register(:foo).
|
22
|
+
expect(subject).to receive(:value).with(:foo, {}).and_return("bar")
|
23
|
+
expect(subject.register(:foo)).to eq(subject)
|
24
24
|
end
|
25
25
|
|
26
26
|
context "when there is a missing constant while registering" do
|
@@ -12,11 +12,11 @@ describe DispatchRider::Runner do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
example do
|
15
|
-
subscriber.
|
16
|
-
subscriber.
|
17
|
-
subscriber.
|
18
|
-
subscriber.
|
19
|
-
subscriber.
|
15
|
+
expect(subscriber).to receive(:new).once.and_return(subscriber)
|
16
|
+
expect(subscriber).to receive(:register_queue).once
|
17
|
+
expect(subscriber).to receive(:setup_demultiplexer).once
|
18
|
+
expect(subscriber).to receive(:process).once
|
19
|
+
allow(subscriber).to receive(:register_handler)
|
20
20
|
|
21
21
|
described_class.run
|
22
22
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dispatch-rider
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Suman Mukherjee
|
@@ -11,64 +11,82 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2015-04-
|
14
|
+
date: 2015-04-14 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|
18
18
|
requirement: !ruby/object:Gem::Requirement
|
19
19
|
requirements:
|
20
|
+
- - "~>"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '4'
|
20
23
|
- - ">="
|
21
24
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
25
|
+
version: 3.2.0
|
23
26
|
type: :runtime
|
24
27
|
prerelease: false
|
25
28
|
version_requirements: !ruby/object:Gem::Requirement
|
26
29
|
requirements:
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '4'
|
27
33
|
- - ">="
|
28
34
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
35
|
+
version: 3.2.0
|
30
36
|
- !ruby/object:Gem::Dependency
|
31
37
|
name: activemodel
|
32
38
|
requirement: !ruby/object:Gem::Requirement
|
33
39
|
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '4'
|
34
43
|
- - ">="
|
35
44
|
- !ruby/object:Gem::Version
|
36
|
-
version:
|
45
|
+
version: 3.2.0
|
37
46
|
type: :runtime
|
38
47
|
prerelease: false
|
39
48
|
version_requirements: !ruby/object:Gem::Requirement
|
40
49
|
requirements:
|
50
|
+
- - "~>"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '4'
|
41
53
|
- - ">="
|
42
54
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
55
|
+
version: 3.2.0
|
44
56
|
- !ruby/object:Gem::Dependency
|
45
57
|
name: daemons
|
46
58
|
requirement: !ruby/object:Gem::Requirement
|
47
59
|
requirements:
|
48
|
-
- - "
|
60
|
+
- - "~>"
|
49
61
|
- !ruby/object:Gem::Version
|
50
|
-
version: '
|
62
|
+
version: '1.2'
|
51
63
|
type: :runtime
|
52
64
|
prerelease: false
|
53
65
|
version_requirements: !ruby/object:Gem::Requirement
|
54
66
|
requirements:
|
55
|
-
- - "
|
67
|
+
- - "~>"
|
56
68
|
- !ruby/object:Gem::Version
|
57
|
-
version: '
|
69
|
+
version: '1.2'
|
58
70
|
- !ruby/object:Gem::Dependency
|
59
71
|
name: retries
|
60
72
|
requirement: !ruby/object:Gem::Requirement
|
61
73
|
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0.0'
|
62
77
|
- - ">="
|
63
78
|
- !ruby/object:Gem::Version
|
64
|
-
version:
|
79
|
+
version: 0.0.5
|
65
80
|
type: :runtime
|
66
81
|
prerelease: false
|
67
82
|
version_requirements: !ruby/object:Gem::Requirement
|
68
83
|
requirements:
|
84
|
+
- - "~>"
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0.0'
|
69
87
|
- - ">="
|
70
88
|
- !ruby/object:Gem::Version
|
71
|
-
version:
|
89
|
+
version: 0.0.5
|
72
90
|
description: "\n Messaging system based on the reactor pattern.\n\n You can
|
73
91
|
publish messages to a queue and then a demultiplexer\n runs an event loop which
|
74
92
|
pops items from the queue and hands\n it over to a dispatcher.\n\n The dispatcher
|
@@ -95,6 +113,7 @@ files:
|
|
95
113
|
- lib/dispatch-rider/callbacks.rb
|
96
114
|
- lib/dispatch-rider/callbacks/access.rb
|
97
115
|
- lib/dispatch-rider/callbacks/storage.rb
|
116
|
+
- lib/dispatch-rider/callbacks/support.rb
|
98
117
|
- lib/dispatch-rider/command.rb
|
99
118
|
- lib/dispatch-rider/configuration.rb
|
100
119
|
- lib/dispatch-rider/debug.rb
|
@@ -214,7 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
214
233
|
version: '0'
|
215
234
|
requirements: []
|
216
235
|
rubyforge_project:
|
217
|
-
rubygems_version: 2.
|
236
|
+
rubygems_version: 2.4.5
|
218
237
|
signing_key:
|
219
238
|
specification_version: 4
|
220
239
|
summary: Messaging system that is customizable based on which queueing system we are
|