bi-frost 0.3.1 → 0.3.2

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: 411dc7aed154c803362268cf06d0f14b26754adf
4
- data.tar.gz: c5ce6bd8a38fc2040972ca3b3debf56d1aaf150f
3
+ metadata.gz: 986bfabd346d59957dd78009b4ea2170214dcd0d
4
+ data.tar.gz: e9454650e4be44971f021473143866bc22f31af6
5
5
  SHA512:
6
- metadata.gz: 2adc9df5efee3768aad4704ae356fb32c4154146dcce4845928d02ec57ac52b171d97258c393f2f1eb7fa2b2d3ac500d7fb7ad2fabe6cb9916d399ef12674171
7
- data.tar.gz: 43c9e7c276de096a0de5c392e462761e8147d915457f3c30b74fb55608440b4a462c689c02847c463698b692daa38662d4f33a1eab3a43502a6a412c9ca0aa6f
6
+ metadata.gz: bb982048b43860fed16c4e7af9058d9fdb34c206420c67c02d047e2763a9b5510d4599e94e2952e41d297832806de3c8df79966e9acb0ff528e79a4bb3d6830d
7
+ data.tar.gz: d19145821ad14b54be7ec645959956c1a93059d58a8cf618a82b5fd8d8f8e262ef5a9fae40c427da552a2c411d41edce06959993c3969672519e9a3a460f21f5
data/lib/bifrost.rb CHANGED
@@ -11,7 +11,9 @@ require 'bifrost/exceptions/invalid_worker_definition_error'
11
11
  require 'bifrost/exceptions/message_delivery_error'
12
12
  require 'bifrost/exceptions/unsupported_lambda_error'
13
13
 
14
- require 'celluloid'
14
+ # Set Celluloid's debug mode to true if the Bifrost is set to report as well
15
+ require 'celluloid/debug' if ENV['BIFROST_DEBUG']
16
+ require 'celluloid/current'
15
17
 
16
18
  # Bifrost is a pub/sub gem built on top of the Azure MessageBus system
17
19
  module Bifrost
@@ -21,6 +23,12 @@ module Bifrost
21
23
  Celluloid.logger = log_provider
22
24
  end
23
25
 
26
+ # Helper method for other types in the Bifrost to know when logging
27
+ # is turned on
28
+ def self.debug?
29
+ ENV['BIFROST_DEBUG']
30
+ end
31
+
24
32
  # Simple utlity that creates a topic and a single subscriber for the given
25
33
  # topic. The topic is returned
26
34
  def self.create_topic_with_subscriber(topic, subscriber)
@@ -8,6 +8,7 @@ module Bifrost
8
8
  attr_reader :subject, :body, :status, :message_id
9
9
 
10
10
  alias_method :resource_id, :message_id
11
+ alias_method :id, :message_id
11
12
 
12
13
  # A message must have a valid subject and body. The service
13
14
  # bus is initialised in the Entity class
@@ -43,6 +44,11 @@ module Bifrost
43
44
  end
44
45
  end
45
46
 
47
+ # A message when serialised to a string just renders the messag identifier
48
+ def to_s
49
+ id
50
+ end
51
+
46
52
  private
47
53
 
48
54
  # Merges this message with the required properties of the raw Azure brokered message
@@ -9,7 +9,7 @@ module Bifrost
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 = 2
13
13
 
14
14
  # The full version as a string.
15
15
  VERSION = "#{MAJOR_VERSION}.#{MINOR_VERSION}.#{PATCH_VERSION}".freeze
@@ -21,16 +21,18 @@ module Bifrost
21
21
  @subscriber ||= subscriber
22
22
  @callback ||= callback
23
23
  super()
24
- info("Worker #{to_sym} starting up...")
24
+ info("Worker #{self} starting up...")
25
25
  publish('worker_ready', topic, subscriber)
26
26
  end
27
27
 
28
28
  # This method starts the actor, which runs in an infinite loop. This means the worker should
29
29
  # not terminate, but if it does, the supervisor will make sure it restarts
30
30
  def run
31
- info("Worker #{to_sym} running...")
31
+ info("Worker #{self} running...")
32
32
  loop do
33
+ info("Worker #{self} waking up...") if Bifrost.debug?
33
34
  read_message
35
+ info("Worker #{self} going to sleep...") if Bifrost.debug?
34
36
  sleep(ENV['QUEUE_DELAY'] || 10)
35
37
  end
36
38
  end
@@ -57,9 +59,12 @@ module Bifrost
57
59
  def read_message
58
60
  raw_message = @bus.interface.receive_subscription_message(topic, subscriber, timeout: ENV['TIMEOUT'] || 10)
59
61
  if raw_message
62
+ info("Worker #{self} picked up message #{raw_message}") if Bifrost.debug?
60
63
  message = Bifrost::Message.new(raw_message)
61
64
  callback.call(message)
62
65
  @bus.interface.delete_subscription_message(raw_message)
66
+ else
67
+ info("Worker #{self} no message...") if Bifrost.debug?
63
68
  end
64
69
  end
65
70
  end
data/spec/spec_helper.rb CHANGED
@@ -1,16 +1,19 @@
1
1
  require 'azure'
2
- require 'bifrost'
3
2
  require 'byebug'
4
3
  require 'dotenv'
5
4
  require 'simplecov'
6
5
 
6
+ # Load environment variables for Azure
7
+ Dotenv.load('.env.test')
8
+
9
+ # We need to load the environment before the bifrost
10
+ require 'bifrost'
11
+
7
12
  SimpleCov.start do
8
13
  add_filter '/spec/'
9
14
  end
10
15
 
11
16
  RSpec.configure do |config|
12
- # Load environment variables for Azure
13
- Dotenv.load('.env.test')
14
17
 
15
18
  # All specs use this pre-defined namespace in Azure
16
19
  Azure.sb_namespace = ENV['AZURE_BUS_NAMESPACE']
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.3.1
4
+ version: 0.3.2
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-18 00:00:00.000000000 Z
11
+ date: 2016-11-19 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.4.5.1
203
+ rubygems_version: 2.5.1
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