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 +4 -4
- data/lib/bifrost/manager.rb +9 -2
- data/lib/bifrost/version.rb +2 -2
- data/lib/bifrost/worker.rb +10 -4
- data/spec/bifrost/manager_spec.rb +10 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ab76d504bbb328cedf3acd5717d455acb79867d
|
4
|
+
data.tar.gz: c8a72d0ecf9f08f3b072ef31b4e1a0a010c8dc8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73a898d4281aa3c2107bb99c6776baf217a843a468414d31b830761dfb39e3c20d9c787770c7168f51d29f2e17936247a0b28aeac569833e50a4a2dfc372dd8b
|
7
|
+
data.tar.gz: 2c25a237b5df367a21f5eb4e6234db02cb38831d0a9789378b2a253fcd45ec65fe0273977740a65146e1e8c5f7da67ff6ae1fa224f8475dc4e107d5834b3b400
|
data/lib/bifrost/manager.rb
CHANGED
@@ -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)
|
data/lib/bifrost/version.rb
CHANGED
@@ -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 =
|
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 =
|
12
|
+
PATCH_VERSION = 0
|
13
13
|
|
14
14
|
# The full version as a string.
|
15
15
|
VERSION = "#{MAJOR_VERSION}.#{MINOR_VERSION}.#{PATCH_VERSION}".freeze
|
data/lib/bifrost/worker.rb
CHANGED
@@ -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
|
-
|
65
|
-
|
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
|
+
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:
|
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.
|
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
|