bi-frost 0.4.1 → 0.5.0

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: e3473e63e0afb70a565b476a6ff3b8e65ef87f96
4
- data.tar.gz: df2842a9f4838f55156ea570c0c5a476326ec4bd
3
+ metadata.gz: 0ab76d504bbb328cedf3acd5717d455acb79867d
4
+ data.tar.gz: c8a72d0ecf9f08f3b072ef31b4e1a0a010c8dc8e
5
5
  SHA512:
6
- metadata.gz: 0dfb17e4d710b6e52e70d13ef610878cb3086e2e007cf4549e72f53c381ff5f0e94109275d500a0ceefe60d4703e00cdb0e5a6ce52794a6c06887321a2816b6e
7
- data.tar.gz: db30185a5cab2f29980fc8d59575207bd81df1887d66847013396b323c787e2088d3710597da7c6c20012ce337df5b2881688d96036eaaa9c8351eecf43d4e4b
6
+ metadata.gz: 73a898d4281aa3c2107bb99c6776baf217a843a468414d31b830761dfb39e3c20d9c787770c7168f51d29f2e17936247a0b28aeac569833e50a4a2dfc372dd8b
7
+ data.tar.gz: 2c25a237b5df367a21f5eb4e6234db02cb38831d0a9789378b2a253fcd45ec65fe0273977740a65146e1e8c5f7da67ff6ae1fa224f8475dc4e107d5834b3b400
@@ -21,11 +21,11 @@ module Bifrost
21
21
 
22
22
  # A supervised worker can be added to the current collection of supervised workers
23
23
  # this also starts the actor
24
- def add(topic, subscriber, proc)
24
+ def add(topic, subscriber, proc, options = {})
25
25
  if topic.nil? || subscriber.nil? || proc.nil?
26
26
  raise InvalidWorkerDefinitionError, 'Invalid worker'
27
27
  else
28
- Worker.supervise(as: Worker.handle(topic, subscriber), args: [topic, subscriber, proc])
28
+ Worker.supervise(as: Worker.handle(topic, subscriber), args: [topic, subscriber, proc, append_default_options(options)])
29
29
  end
30
30
  end
31
31
 
@@ -59,6 +59,13 @@ module Bifrost
59
59
 
60
60
  private
61
61
 
62
+ ##
63
+ # Create default options hash if custom options do not exit
64
+ def append_default_options(custom_options)
65
+ options = { non_repeatable: false }
66
+ options.merge(custom_options)
67
+ end
68
+
62
69
  # Retrieve a worker through the supervisory structure, this can take a while as the worker might
63
70
  # be going through a restart procedure by the actor framework
64
71
  def get_worker(topic, subscriber)
@@ -5,11 +5,11 @@ module Bifrost
5
5
  MAJOR_VERSION = 0
6
6
 
7
7
  # The minor version of Bifrost, updated for new feature releases.
8
- MINOR_VERSION = 4
8
+ MINOR_VERSION = 5
9
9
 
10
10
  # The patch version of Bifrost, updated only for bug fixes from the last
11
11
  # feature release.
12
- PATCH_VERSION = 1
12
+ PATCH_VERSION = 0
13
13
 
14
14
  # The full version as a string.
15
15
  VERSION = "#{MAJOR_VERSION}.#{MINOR_VERSION}.#{PATCH_VERSION}".freeze
@@ -12,14 +12,15 @@ module Bifrost
12
12
  include Celluloid::Internals::Logger
13
13
  include Celluloid::Notifications
14
14
 
15
- attr_reader :topic, :subscriber, :callback
15
+ attr_reader :topic, :subscriber, :callback, :options
16
16
 
17
17
  # Initialise the worker/actor. This actually starts the worker by implicitly calling the run method
18
- def initialize(topic, subscriber, callback)
18
+ def initialize(topic, subscriber, callback, options = {})
19
19
  raise Bifrost::Exceptions::UnsupportedLambdaError, 'callback is not a proc' unless callback.respond_to?(:call)
20
20
  @topic ||= topic
21
21
  @subscriber ||= subscriber
22
22
  @callback ||= callback
23
+ @options ||= options
23
24
  super()
24
25
  info("Worker #{self} starting up...")
25
26
  publish('worker_ready', topic, subscriber)
@@ -61,8 +62,13 @@ module Bifrost
61
62
  if raw_message
62
63
  info("Worker #{self} picked up message #{raw_message}") if Bifrost.debug?
63
64
  message = Bifrost::Message.new(raw_message)
64
- callback.call(message)
65
- @bus.interface.delete_subscription_message(raw_message)
65
+ if options[:non_repeatable]
66
+ @bus.interface.delete_subscription_message(raw_message)
67
+ callback.call(message)
68
+ else
69
+ callback.call(message)
70
+ @bus.interface.delete_subscription_message(raw_message)
71
+ end
66
72
  elsif Bifrost.debug?
67
73
  info("Worker #{self} no message...")
68
74
  end
@@ -10,4 +10,14 @@ describe Bifrost::Manager do
10
10
  manager.add('topicX', 'blah', proc { |m| puts "Secondary Received: message #{m}" })
11
11
  manager.run
12
12
  end
13
+
14
+ it 'should append default options to empty options param' do
15
+ manager.add('topicX', 'blah', proc { |m| puts "Secondary Received: message #{m}" })
16
+ expect(manager.send(:append_default_options, {})).to eq({ non_repeatable: false })
17
+ end
18
+
19
+ it 'should append default options to custom options param' do
20
+ manager.add('topicX', 'blah', proc { |m| puts "Secondary Received: message #{m}" })
21
+ expect(manager.send(:append_default_options, { custom_option: true })).to eq({ custom_option: true, non_repeatable: false })
22
+ end
13
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bi-frost
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shirren Premaratne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-23 00:00:00.000000000 Z
11
+ date: 2017-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: azure
@@ -200,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
200
  version: '0'
201
201
  requirements: []
202
202
  rubyforge_project:
203
- rubygems_version: 2.5.1
203
+ rubygems_version: 2.4.8
204
204
  signing_key:
205
205
  specification_version: 4
206
206
  summary: Bifrost is a pub/sub wrapper library which uses the Azure message bus and