cpi-event-connector 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,12 +26,14 @@ module Cpi
26
26
  def start
27
27
  return if @started
28
28
 
29
+ Event.logger.debug "Connecting to Rabbit with params #{@params.inspect}"
29
30
  @bunny = Bunny.new @params
30
31
  @bunny.start
31
32
  @bunny.tx_select
32
33
  @exchange = @bunny.exchange('')
33
34
 
34
35
  @started = true
36
+ Event.logger.debug "Connection established"
35
37
  end
36
38
 
37
39
  def with_retries(*args, &block)
@@ -47,12 +49,15 @@ module Cpi
47
49
  begin
48
50
  yield
49
51
  rescue *exceptions => e
52
+ Event.logger.debug "Exception caught in #with_retries:\n#{e.message}"
50
53
  if retried < options[:retries]
51
54
  retried += 1
55
+ Event.logger.debug "Trying again. Have tried #{retried} times so far."
52
56
  sleep options[:sleep]
53
57
  options[:before_retry].call
54
58
  retry
55
59
  else
60
+ Event.logger.debug "Gave up on retries, throwing: #{e.message}"
56
61
  raise e
57
62
  end
58
63
  end
@@ -4,21 +4,31 @@ module Cpi
4
4
  class Event
5
5
  class << self
6
6
  attr_accessor :connection_params
7
+ attr_accessor :logger
7
8
  end
8
9
 
9
10
  @enabled = false
11
+ @logger = Logger.new("/dev/null")
10
12
 
11
- def self.configure(params)
13
+ def self.configure(params, logger)
14
+ @logger = logger
15
+ @logger.info "CPI Event Connector initialized"
12
16
  @enabled = !!params.delete(:enabled)
17
+ @logger.info "CPI Event Connector is " + (@enabled ? "" : "not ") + "enabled"
13
18
  self.connection_params = params
14
19
  end
15
20
 
16
21
  def self.transmit(event_type, tenant_uid, root_path, options=nil)
17
- return unless @enabled
22
+ if !@enabled
23
+ @logger.debug "Aborting transmit because CPI Event Connector not enabled"
24
+ return
25
+ end
18
26
  raise ArgumentError, "Tenant UID must be specified" if tenant_uid.blank?
19
27
 
20
28
  event_json = Cpi::Generator.create_event(event_type, tenant_uid, root_path)
29
+ @logger.debug "Transmitting message '#{event_json}'"
21
30
  self.connector.transmit(event_json, options)
31
+ @logger.debug "Transmission complete"
22
32
  end
23
33
 
24
34
  private
@@ -1,3 +1,3 @@
1
1
  module Cpi
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
data/spec/event_spec.rb CHANGED
@@ -5,15 +5,22 @@ require 'unification_assertion'
5
5
 
6
6
  describe Cpi::Event do
7
7
  let(:config) { { :enabled => true, :key => "value" } }
8
+ let(:logger) { stub("Logger", debug: nil, info: nil) }
8
9
 
9
10
  describe ".configure" do
10
11
  let(:connector) { double(Cpi::Connector) }
11
12
 
12
13
  it "accepts a hash of connection information" do
13
- Cpi::Event.configure(config)
14
+ Cpi::Event.configure(config, logger)
14
15
 
15
16
  Cpi::Event.connection_params.should == { :key => "value" }
16
17
  end
18
+
19
+ it "accepts a logger and sets it as a class variable" do
20
+ Cpi::Event.configure({}, logger)
21
+
22
+ Cpi::Event.logger.should == logger
23
+ end
17
24
  end
18
25
 
19
26
  describe ".transmit" do
@@ -28,7 +35,7 @@ describe Cpi::Event do
28
35
  let(:content) { "<test />" }
29
36
 
30
37
  it "generates and sends an event" do
31
- Cpi::Event.configure(real_config)
38
+ Cpi::Event.configure(real_config, logger)
32
39
 
33
40
  Cpi::Event.transmit("shipment_shipped", "stuff", content)
34
41
 
@@ -43,7 +50,7 @@ describe Cpi::Event do
43
50
  end
44
51
 
45
52
  it "creates a connection for each thread" do
46
- Cpi::Event.configure(config)
53
+ Cpi::Event.configure(config, logger)
47
54
 
48
55
  connector1 = double("connector 1")
49
56
  connector2 = double("connector 2")
@@ -64,7 +71,7 @@ describe Cpi::Event do
64
71
  it "does not transmit when it is not enabled" do
65
72
  real_config[:enabled] = false
66
73
 
67
- Cpi::Event.configure(real_config)
74
+ Cpi::Event.configure(real_config, logger)
68
75
  Cpi::Generator.should_not_receive(:create_event)
69
76
  # And there shouldn't be an exception
70
77
 
@@ -72,12 +79,13 @@ describe Cpi::Event do
72
79
  end
73
80
 
74
81
  it "does nothing when called before being configured" do
82
+ Cpi::Event.logger = stub(debug: nil)
75
83
  Cpi::Generator.should_not_receive(:create_event)
76
84
  Cpi::Event.transmit("message", "tenant_uid", "content")
77
85
  end
78
86
 
79
87
  it "raises exception when no tenant_uid is passed in" do
80
- Cpi::Event.configure(real_config)
88
+ Cpi::Event.configure(real_config, logger)
81
89
  Cpi::Generator.should_not_receive(:create_event)
82
90
  expect {Cpi::Event.transmit("message", nil, "content")}.to raise_error(ArgumentError)
83
91
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cpi-event-connector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-08-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: !ruby/object:Gem::Requirement
16
+ requirement: &23871620 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,15 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
24
+ version_requirements: *23871620
30
25
  - !ruby/object:Gem::Dependency
31
26
  name: backports
32
- requirement: !ruby/object:Gem::Requirement
27
+ requirement: &23871200 !ruby/object:Gem::Requirement
33
28
  none: false
34
29
  requirements:
35
30
  - - ! '>='
@@ -37,15 +32,10 @@ dependencies:
37
32
  version: '0'
38
33
  type: :development
39
34
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
35
+ version_requirements: *23871200
46
36
  - !ruby/object:Gem::Dependency
47
37
  name: justinf-unification_assertion
48
- requirement: !ruby/object:Gem::Requirement
38
+ requirement: &23870780 !ruby/object:Gem::Requirement
49
39
  none: false
50
40
  requirements:
51
41
  - - ! '>='
@@ -53,15 +43,10 @@ dependencies:
53
43
  version: '0'
54
44
  type: :development
55
45
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
46
+ version_requirements: *23870780
62
47
  - !ruby/object:Gem::Dependency
63
48
  name: bunny
64
- requirement: !ruby/object:Gem::Requirement
49
+ requirement: &23870360 !ruby/object:Gem::Requirement
65
50
  none: false
66
51
  requirements:
67
52
  - - ! '>='
@@ -69,15 +54,10 @@ dependencies:
69
54
  version: '0'
70
55
  type: :runtime
71
56
  prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
57
+ version_requirements: *23870360
78
58
  - !ruby/object:Gem::Dependency
79
59
  name: activesupport
80
- requirement: !ruby/object:Gem::Requirement
60
+ requirement: &23869860 !ruby/object:Gem::Requirement
81
61
  none: false
82
62
  requirements:
83
63
  - - ~>
@@ -85,15 +65,10 @@ dependencies:
85
65
  version: '3'
86
66
  type: :runtime
87
67
  prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ~>
92
- - !ruby/object:Gem::Version
93
- version: '3'
68
+ version_requirements: *23869860
94
69
  - !ruby/object:Gem::Dependency
95
70
  name: uuidtools
96
- requirement: !ruby/object:Gem::Requirement
71
+ requirement: &23869360 !ruby/object:Gem::Requirement
97
72
  none: false
98
73
  requirements:
99
74
  - - ~>
@@ -101,12 +76,7 @@ dependencies:
101
76
  version: 2.1.2
102
77
  type: :runtime
103
78
  prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ~>
108
- - !ruby/object:Gem::Version
109
- version: 2.1.2
79
+ version_requirements: *23869360
110
80
  description: see summary
111
81
  email:
112
82
  - engineering@nulogy.com
@@ -150,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
120
  version: '0'
151
121
  requirements: []
152
122
  rubyforge_project:
153
- rubygems_version: 1.8.24
123
+ rubygems_version: 1.8.10
154
124
  signing_key:
155
125
  specification_version: 3
156
126
  summary: Sends events to CPI