dispatch-rider 0.1.0 → 0.1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7bbb3c1f98b4bafe69fae92ea7508cd67345275a
4
- data.tar.gz: b849394b852851fa7d29f25338ef17a1870ad8b3
3
+ metadata.gz: 31cdb85057c6ea3503bdc6dfa5b8b38f00d6bd6c
4
+ data.tar.gz: d5e696a46f34de63cc27c28c6f607ad44b075b77
5
5
  SHA512:
6
- metadata.gz: dc1538bee183a3e7f03e0e06e141704e1abb7cdc7e765d9e69918ada0bd90fcc836a29f6440822a83c16fe7d7469bbe95735ffeb753995974beed6485698e34f
7
- data.tar.gz: bcbe7f23996a3dcf324b64598db790b02886c83b1afa37c0085711cd688a0aad63096849c0fbf35753f6fba7ba231014590390b1168389754af8d08e3b1d2e96
6
+ metadata.gz: 4a1b52c405eb89d2b933f64ca9bdbe8b7d4a11943d4d004f484972ea6b1c3f281c6bd92b062611c6d22b3d082f0655833974e06fdafd0f8ef9f8ac9b3aeed0fe
7
+ data.tar.gz: e854d367746c8903c4cdc7aabe4dd8bbff0b815e3a91b383fa5348aa374741942cbfd18ca8571927ee174bf6b0ed4a750849cf803786c331947eafed5fa64fb3
data/README.md CHANGED
@@ -180,6 +180,13 @@ DispatchRider.config do |config|
180
180
  # code to run after process
181
181
  end
182
182
 
183
+ # allows you to wrap a callback around the execution of each job
184
+ config.around(:dispatch_message) do |job, message|
185
+ some_block_around do
186
+ job.call
187
+ end
188
+ end
189
+
183
190
  config.error_handler = DefaultErrorHandler # an object that responds to .call(message, exception)
184
191
 
185
192
  config.queue_kind = :sqs
@@ -189,6 +196,19 @@ DispatchRider.config do |config|
189
196
  end
190
197
  ```
191
198
 
199
+ ### Callbacks
200
+
201
+ Dispatch rider supports injecting callbacks in a few parts of the
202
+ lifecycle of the process.
203
+
204
+ ```
205
+ :initialize - when the runner is being initialized
206
+ :process - when the runner is running its event loop
207
+ :dispatch_message - around the execution of a single message (the block is passed the job )
208
+ ```
209
+
210
+ Each callback can have hooks plugged into it at `before`, `after` and `around` the execution.
211
+
192
212
  ### Manual Setup
193
213
 
194
214
  To setup a subscriber you'll need message handlers. The handlers are named the same as the message subjects.
@@ -7,21 +7,15 @@ module DispatchRider
7
7
  @callbacks = callbacks
8
8
  end
9
9
 
10
- def invoke(event, *args)
11
- begin
12
- invoke_callbacks :before, event, *args
13
- yield
14
- ensure
15
- invoke_callbacks :after, event, *args
16
- end
17
- end
10
+ def invoke(event, *args, &block)
11
+ action_proc = block
18
12
 
19
- private
20
-
21
- def invoke_callbacks(modifier, event, *args)
22
- callbacks.for(modifier, event).each do |callback|
23
- callback.call(*args)
13
+ callbacks.for(event).reverse.each do |filter_block|
14
+ current_action = action_proc
15
+ action_proc = proc { filter_block.call(current_action, *args) }
24
16
  end
17
+
18
+ action_proc.call
25
19
  end
26
20
 
27
21
  end
@@ -7,23 +7,29 @@ module DispatchRider
7
7
  end
8
8
 
9
9
  def before(event, block_param = nil, &block)
10
- add_callback :before, event, block_param, &block
10
+ around(event) do |job, *args|
11
+ (block_param || block).call(*args)
12
+ job.call
13
+ end
11
14
  end
12
15
 
13
16
  def after(event, block_param = nil, &block)
14
- add_callback :after, event, block_param, &block
17
+ around(event) do |job, *args|
18
+ begin
19
+ job.call
20
+ ensure
21
+ (block_param || block).call(*args)
22
+ end
23
+ end
15
24
  end
16
25
 
17
- def for(modifier, event)
18
- @callbacks[[modifier, event]] || []
26
+ def around(event, block_param = nil, &block)
27
+ @callbacks[event] ||= []
28
+ @callbacks[event] << (block_param || block)
19
29
  end
20
30
 
21
- private
22
-
23
- def add_callback(modifier, event, block_param = nil, &block)
24
- block = block || block_param
25
- @callbacks[[modifier, event]] ||= []
26
- @callbacks[[modifier, event]] << block
31
+ def for(event)
32
+ @callbacks[event] || []
27
33
  end
28
34
 
29
35
  end
@@ -12,7 +12,7 @@ module DispatchRider
12
12
  @subscriber = DispatchRider::Subscriber
13
13
  end
14
14
 
15
- delegate :before, :after, :to => :callbacks
15
+ delegate :before, :after, :around, :to => :callbacks
16
16
 
17
17
  def handlers
18
18
  @handlers ||= begin
@@ -3,6 +3,8 @@
3
3
  # Tha handlers need to be modules that implement the process method.
4
4
  # What handler to dispatch the message to is figured out from the subject of the message.
5
5
 
6
+ require 'forwardable'
7
+
6
8
  module DispatchRider
7
9
  class Dispatcher
8
10
  extend Forwardable
@@ -16,9 +18,21 @@ module DispatchRider
16
18
  end
17
19
 
18
20
  def dispatch(message)
19
- handler_registrar.fetch(message.subject).new.do_process(message.body)
21
+ callbacks.invoke(:dispatch_message, message) do
22
+ handler_registrar.fetch(message.subject).new.do_process(message.body)
23
+ end
20
24
  true # success => true (delete message)
21
25
  end
22
26
 
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
+
23
37
  end
24
38
  end
@@ -3,6 +3,9 @@
3
3
  # The expected usage is as follows :
4
4
  # notification_service = DispatchRider::NotificationServices::Base.new
5
5
  # notification_service.publish(:to => [:foo, :oof], :message => {:subject => "bar", :body => "baz"})
6
+
7
+ require 'forwardable'
8
+
6
9
  module DispatchRider
7
10
  module NotificationServices
8
11
  class Base
@@ -1,4 +1,4 @@
1
1
  # This file specifies the current version of the gem.
2
2
  module DispatchRider
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1.1"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dispatch-rider
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Suman Mukherjee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-24 00:00:00.000000000 Z
11
+ date: 2013-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport