superbolt 0.1.6 → 0.2.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: 34069be8f4689aa269cf82304fed8ca450cf30c6
4
- data.tar.gz: 5310a1c39534aae35cc76624cbb1d200cd9cbfa9
3
+ metadata.gz: 2702ec5e662440bb59aeded52529c4561bf09574
4
+ data.tar.gz: 07bdfbf076a3ef783d0b36c5f35a603e4c2a93bc
5
5
  SHA512:
6
- metadata.gz: 5acdf639a27305f47f0b8db5852c50fb482daa3a7c2d8ebedb63188df96ebb66999faaa75e156b9e33f890133cd298410c99b1f09c6e0ef524a2c8956384c827
7
- data.tar.gz: 01629e7f989530e35060193436fb72d2c7bed8520553a19da5a1baf1bfba9e7ea0cba8f8821d40dc7ff6949921415cb3398424dd1cdf15c2a5b8305ccaa2face
6
+ metadata.gz: fac26fd38a33473b326f2fbb44fa831b9c1aeb9e1226160a315257ed160702d6b88d43e4831881cc01918f11a57681201ce5198cb39886dd5b96a04cbe7b575b
7
+ data.tar.gz: 7f4881397075fc8dfdd726b46ccb4f2d13095ddb1e13eb0f222975a4a3ecfabafefe80c28cf7375cab8c8efa4a3e42814b907ee6f3a72b3e1c094f48bfddb852
@@ -17,6 +17,7 @@ require "superbolt/incoming_message"
17
17
  require "superbolt/app"
18
18
  require "superbolt/processor"
19
19
  require "superbolt/facade"
20
+ require "superbolt/message_ram"
20
21
  require "superbolt/messenger"
21
22
  require "superbolt/spec_helpers"
22
23
 
@@ -0,0 +1,31 @@
1
+ module Superbolt
2
+ class MessageRam
3
+ attr_reader :messenger, :method_name
4
+ attr_accessor :run_time
5
+ def initialize(messenger, method_name)
6
+ @messenger = messenger
7
+ @method_name = method_name
8
+ @run_time = 0
9
+ end
10
+
11
+ def besiege
12
+ messenger.send(method_name)
13
+ rescue => e
14
+ puts "Something went wrong: #{e}"
15
+ puts "=========================="
16
+ puts "Continuing the siege in #{messenger.retry_time} seconds...\n"
17
+ sleep(messenger.retry_time)
18
+ retreat(e) if retreat?
19
+ besiege
20
+ end
21
+
22
+ def retreat?
23
+ @run_time += messenger.retry_time
24
+ run_time >= messenger.timeout
25
+ end
26
+
27
+ def retreat(error)
28
+ raise error
29
+ end
30
+ end
31
+ end
@@ -1,6 +1,6 @@
1
1
  module Superbolt
2
2
  class Messenger
3
- attr_accessor :origin, :name, :event, :arguments, :env
3
+ attr_accessor :origin, :name, :event, :arguments, :env, :retry_time, :timeout
4
4
 
5
5
  def initialize(options={})
6
6
  @name = options.delete(:to)
@@ -8,6 +8,8 @@ module Superbolt
8
8
  @event = options.delete(:event) || self.class.defaultevent
9
9
  @env = Superbolt.env
10
10
  @arguments = options
11
+ @retry_time = Superbolt.config.options[:retry_time] || 10
12
+ @timeout = Superbolt.config.options[:timeout] || 60
11
13
  end
12
14
 
13
15
  def message
@@ -36,6 +38,14 @@ module Superbolt
36
38
  attr_chainer(:arguments, val)
37
39
  end
38
40
 
41
+ def retry_after(val=nil)
42
+ attr_chainer(:retry_time, val)
43
+ end
44
+
45
+ def timeout_after(val=nil)
46
+ attr_chainer(:timeout, val)
47
+ end
48
+
39
49
  def attr_chainer(attr, val)
40
50
  return send(attr) unless val
41
51
  self.send("#{attr}=", val)
@@ -47,6 +57,10 @@ module Superbolt
47
57
 
48
58
  def send!(args=nil)
49
59
  self.arguments = args if args
60
+ MessageRam.new(self, 'push_to_queue').besiege
61
+ end
62
+
63
+ def push_to_queue
50
64
  queue.push(message)
51
65
  end
52
66
 
@@ -1,3 +1,3 @@
1
1
  module Superbolt
2
- VERSION = "0.1.6"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe Superbolt::MessageRam do
4
+ let(:error_class) { Exception }
5
+ let(:messenger) { double(
6
+ retry_time: 1,
7
+ timeout: 5
8
+ )}
9
+ let(:ram) { Superbolt::MessageRam.new(messenger, :some_method ) }
10
+
11
+ before do
12
+ messenger.should_receive(:some_method).ordered.and_raise('Some Error')
13
+ end
14
+
15
+ context "failed to open connection" do
16
+ before do
17
+ expect(messenger)
18
+ .to receive(:some_method).ordered
19
+ .and_return(true)
20
+ end
21
+
22
+ it 'should raise no errors' do
23
+ expect {
24
+ ram.besiege
25
+ }.to_not raise_error
26
+ end
27
+
28
+ it "retries on a configured interval" do
29
+ ram.besiege.should == true
30
+ end
31
+ end
32
+
33
+ context 'it runs out of time' do
34
+ before do
35
+ ram.run_time = 6
36
+ end
37
+ it 'should raise error' do
38
+ expect {
39
+ ram.besiege
40
+ }.to raise_error(Exception)
41
+ end
42
+ end
43
+ end
@@ -66,7 +66,7 @@ describe Superbolt::Messenger do
66
66
 
67
67
  it '#from returns the origin' do
68
68
  messenger.from('activator')
69
- messenger.fromq.should == 'activator'
69
+ messenger.from.should == 'activator'
70
70
  end
71
71
 
72
72
  it '#re returns the event' do
@@ -78,11 +78,64 @@ describe Superbolt::Messenger do
78
78
  messenger.data({foo: 'bar'})
79
79
  messenger.data.should == {foo: 'bar'}
80
80
  end
81
+
82
+ describe '#retry_time' do
83
+ before do
84
+ Superbolt.config.options[:retry_time] = nil
85
+ end
86
+
87
+ context 'config contains retry_time' do
88
+ it 'returns config value' do
89
+ Superbolt.config.options[:retry_time] = 12
90
+ messenger.retry_after.should == 12
91
+ end
92
+ end
93
+
94
+ context 'config does not contain retry_time but we pass it in' do
95
+ it 'returns passed in value' do
96
+ messenger.retry_after(11)
97
+ messenger.retry_after.should == 11
98
+ end
99
+ end
100
+
101
+ context 'config does not contain retry_time and we dont pass it in' do
102
+ it 'returns default value' do
103
+ messenger.retry_after.should == 10
104
+ end
105
+ end
106
+ end
107
+
108
+ describe '#retry_time' do
109
+ before do
110
+ Superbolt.config.options[:timeout] = nil
111
+ end
112
+
113
+ context 'config contains retry_time' do
114
+ it 'returns config value' do
115
+ Superbolt.config.options[:timeout] = 120
116
+ messenger.timeout_after.should == 120
117
+ end
118
+ end
119
+
120
+ context 'config does not contain retry_time but we pass it in' do
121
+ it 'returns passed in value' do
122
+ messenger.timeout_after(90)
123
+ messenger.timeout_after.should == 90
124
+ end
125
+ end
126
+
127
+ context 'config does not contain retry_time and we dont pass it in' do
128
+ it 'returns default value' do
129
+ messenger.timeout_after.should == 60
130
+ end
131
+ end
132
+ end
81
133
  end
82
134
  end
83
135
 
84
136
  describe 'send!' do
85
137
  before do
138
+ Superbolt.config.options[:retry_time] = 0
86
139
  messenger
87
140
  .to(name)
88
141
  .from('me')
@@ -119,7 +119,8 @@ describe 'Superbolt::Queue' do
119
119
  end
120
120
 
121
121
  describe 'errors cases' do
122
- let(:new_queue) { Superbolt::Queue.new("random.name.#{rand(1_000_000)}") }
122
+ let(:new_queue) { Superbolt::Queue.new("superbolt_test") }
123
+ #{rand(1_000_000)}
123
124
 
124
125
  after do
125
126
  new_queue.clear
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: superbolt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - socialchorus
@@ -118,6 +118,7 @@ files:
118
118
  - lib/superbolt/connection/queue.rb
119
119
  - lib/superbolt/facade.rb
120
120
  - lib/superbolt/incoming_message.rb
121
+ - lib/superbolt/message_ram.rb
121
122
  - lib/superbolt/messenger.rb
122
123
  - lib/superbolt/processor.rb
123
124
  - lib/superbolt/queue.rb
@@ -126,6 +127,7 @@ files:
126
127
  - spec/app_spec.rb
127
128
  - spec/config_spec.rb
128
129
  - spec/connection_spec.rb
130
+ - spec/message_ram_spec.rb
129
131
  - spec/messenger_spec.rb
130
132
  - spec/queue_spec.rb
131
133
  - spec/spec_helper.rb
@@ -160,6 +162,7 @@ test_files:
160
162
  - spec/app_spec.rb
161
163
  - spec/config_spec.rb
162
164
  - spec/connection_spec.rb
165
+ - spec/message_ram_spec.rb
163
166
  - spec/messenger_spec.rb
164
167
  - spec/queue_spec.rb
165
168
  - spec/spec_helper.rb