superbolt 0.2.1 → 0.2.3
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/README.md +1 -1
- data/lib/superbolt.rb +1 -3
- data/lib/superbolt/adapter/base.rb +1 -7
- data/lib/superbolt/adapter/bunny.rb +6 -2
- data/lib/superbolt/app.rb +1 -1
- data/lib/superbolt/connection/app.rb +4 -4
- data/lib/superbolt/connection/base.rb +11 -3
- data/lib/superbolt/connection/queue.rb +3 -8
- data/lib/superbolt/facade.rb +2 -0
- data/lib/superbolt/incoming_message.rb +3 -3
- data/lib/superbolt/messenger.rb +3 -6
- data/lib/superbolt/queue.rb +16 -14
- data/lib/superbolt/version.rb +1 -1
- data/spec/connection_spec.rb +7 -4
- data/spec/queue_spec.rb +6 -11
- data/superbolt.gemspec +2 -2
- metadata +19 -23
- data/lib/superbolt/adapter/amqp.rb +0 -18
- data/lib/superbolt/message_ram.rb +0 -31
- data/spec/message_ram_spec.rb +0 -43
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9edf5a20e4fe7b10dc3d4a0ce51ba6db321733a3
|
|
4
|
+
data.tar.gz: 8d46eb9f8f272c78813dadd3555831e130d02276
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 77c29a55feed037520f3f456a1a309b7750493296640ea46f71c3b3174de13223122c0f0f1c116c4db58dd2976f0c686d552b69f15b5dee48c817526540229ff
|
|
7
|
+
data.tar.gz: 019a6f7fff3af4a3b1d4543af28658d7c3ed5d620e09c9c2c99739c9af4ee75178638e87e00c07931f870212474ba07ff55b23da9834dfecb12792969d5a264b
|
data/README.md
CHANGED
data/lib/superbolt.rb
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
require 'json'
|
|
2
2
|
|
|
3
3
|
require 'bunny'
|
|
4
|
-
require 'amqp'
|
|
5
4
|
require 'active_support/core_ext/module/delegation'
|
|
5
|
+
require 'eventmachine'
|
|
6
6
|
|
|
7
7
|
require "superbolt/version"
|
|
8
8
|
require "superbolt/config"
|
|
9
9
|
require "superbolt/adapter/base"
|
|
10
10
|
require "superbolt/adapter/bunny"
|
|
11
|
-
require "superbolt/adapter/amqp"
|
|
12
11
|
require "superbolt/connection/base"
|
|
13
12
|
require "superbolt/connection/queue"
|
|
14
13
|
require "superbolt/connection/app"
|
|
@@ -17,7 +16,6 @@ require "superbolt/incoming_message"
|
|
|
17
16
|
require "superbolt/app"
|
|
18
17
|
require "superbolt/processor"
|
|
19
18
|
require "superbolt/facade"
|
|
20
|
-
require "superbolt/message_ram"
|
|
21
19
|
require "superbolt/messenger"
|
|
22
20
|
require "superbolt/spec_helpers"
|
|
23
21
|
|
|
@@ -5,6 +5,7 @@ module Superbolt
|
|
|
5
5
|
|
|
6
6
|
def initialize(config=nil)
|
|
7
7
|
@config = config || Superbolt.config
|
|
8
|
+
@channel = new_channel
|
|
8
9
|
end
|
|
9
10
|
|
|
10
11
|
delegate :closed?, :open, :open?,
|
|
@@ -16,13 +17,6 @@ module Superbolt
|
|
|
16
17
|
@channel = nil
|
|
17
18
|
response
|
|
18
19
|
end
|
|
19
|
-
|
|
20
|
-
delegate :queues, :acknowledge, :reject, :queue,
|
|
21
|
-
to: :channel
|
|
22
|
-
|
|
23
|
-
def exchange
|
|
24
|
-
channel.default_exchange
|
|
25
|
-
end
|
|
26
20
|
end
|
|
27
21
|
end
|
|
28
22
|
end
|
data/lib/superbolt/app.rb
CHANGED
|
@@ -2,19 +2,19 @@ module Superbolt
|
|
|
2
2
|
module Connection
|
|
3
3
|
class App < Base
|
|
4
4
|
def connection
|
|
5
|
-
|
|
5
|
+
CONNECTION
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
def close(&block)
|
|
9
|
-
|
|
10
|
-
@
|
|
9
|
+
channel.close
|
|
10
|
+
@channel = nil
|
|
11
11
|
@q = nil
|
|
12
12
|
@qq = nil
|
|
13
13
|
block.call
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def qq
|
|
17
|
-
@qq ||=
|
|
17
|
+
@qq ||= channel.queue("#{name}.quit", self.class.default_options)
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
end
|
|
@@ -17,16 +17,24 @@ module Superbolt
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def q
|
|
20
|
-
@q ||=
|
|
20
|
+
@q ||= channel.queue(name, self.class.default_options)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
delegate :exclusive?, :durable?, :auto_delete?,
|
|
24
24
|
to: :q
|
|
25
25
|
|
|
26
26
|
def channel
|
|
27
|
-
|
|
27
|
+
return @channel if @channel.try(:open?)
|
|
28
|
+
tries = 0
|
|
29
|
+
begin
|
|
30
|
+
@channel = connection.new_channel
|
|
31
|
+
rescue ::Bunny::CommandInvalid # only happens if a channel is already open
|
|
32
|
+
@channel.close
|
|
33
|
+
tries += 1
|
|
34
|
+
retry if tries < 2
|
|
35
|
+
end
|
|
28
36
|
end
|
|
29
|
-
|
|
37
|
+
|
|
30
38
|
def self.default_options
|
|
31
39
|
{
|
|
32
40
|
:auto_delete => false,
|
|
@@ -2,12 +2,12 @@ module Superbolt
|
|
|
2
2
|
module Connection
|
|
3
3
|
class Queue < Base
|
|
4
4
|
def connection
|
|
5
|
-
|
|
5
|
+
CONNECTION
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
def close
|
|
9
|
-
|
|
10
|
-
@
|
|
9
|
+
channel.close
|
|
10
|
+
@channel = nil
|
|
11
11
|
@q = nil
|
|
12
12
|
end
|
|
13
13
|
|
|
@@ -16,11 +16,6 @@ module Superbolt
|
|
|
16
16
|
close
|
|
17
17
|
response
|
|
18
18
|
end
|
|
19
|
-
|
|
20
|
-
def writer
|
|
21
|
-
q # to make sure it is connected
|
|
22
|
-
connection.exchange
|
|
23
|
-
end
|
|
24
19
|
end
|
|
25
20
|
end
|
|
26
21
|
end
|
data/lib/superbolt/facade.rb
CHANGED
|
@@ -4,7 +4,7 @@ module Superbolt
|
|
|
4
4
|
|
|
5
5
|
def initialize(delivery_info, payload, channel)
|
|
6
6
|
@payload = payload
|
|
7
|
-
@tag = delivery_info.delivery_tag
|
|
7
|
+
@tag = delivery_info.delivery_tag if delivery_info
|
|
8
8
|
@channel = channel
|
|
9
9
|
end
|
|
10
10
|
|
|
@@ -14,8 +14,8 @@ module Superbolt
|
|
|
14
14
|
payload
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
def reject
|
|
18
|
-
channel.reject(tag)
|
|
17
|
+
def reject(requeue=true)
|
|
18
|
+
channel.reject(tag, requeue)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def ack
|
data/lib/superbolt/messenger.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
module Superbolt
|
|
2
2
|
class Messenger
|
|
3
|
-
attr_accessor :origin, :name, :event, :arguments, :env, :retry_time, :timeout
|
|
3
|
+
attr_accessor :origin, :name, :event, :arguments, :env, :retry_time, :timeout, :live_queue
|
|
4
4
|
|
|
5
5
|
def initialize(options={})
|
|
6
6
|
@name = options.delete(:to)
|
|
@@ -57,18 +57,15 @@ module Superbolt
|
|
|
57
57
|
|
|
58
58
|
def send!(args=nil)
|
|
59
59
|
self.arguments = args if args
|
|
60
|
-
MessageRam.new(self, 'push_to_queue').besiege
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def push_to_queue
|
|
64
60
|
queue.push(message)
|
|
65
61
|
end
|
|
66
62
|
|
|
63
|
+
|
|
67
64
|
def queue
|
|
68
65
|
unless name
|
|
69
66
|
raise "no destination app name defined, please pass one in"
|
|
70
67
|
end
|
|
71
|
-
Queue.new(destination_name)
|
|
68
|
+
@live_queue = Queue.new(destination_name)
|
|
72
69
|
end
|
|
73
70
|
|
|
74
71
|
def destination_name
|
data/lib/superbolt/queue.rb
CHANGED
|
@@ -12,36 +12,36 @@ module Superbolt
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
delegate :close, :closing, :exclusive?, :durable?, :auto_delete?,
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
:channel, :q,
|
|
16
|
+
to: :connection
|
|
17
17
|
|
|
18
18
|
def push(message)
|
|
19
19
|
closing do
|
|
20
|
-
|
|
20
|
+
q.publish(message.to_json)
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def size
|
|
25
|
-
|
|
26
|
-
q.message_count
|
|
27
|
-
end
|
|
25
|
+
q.message_count
|
|
28
26
|
end
|
|
29
27
|
|
|
30
28
|
def clear
|
|
31
|
-
|
|
32
|
-
q.purge
|
|
33
|
-
end
|
|
29
|
+
q.purge
|
|
34
30
|
end
|
|
35
31
|
|
|
36
32
|
# TODO: roll up some of these subscribe methods
|
|
37
33
|
|
|
38
34
|
def read
|
|
35
|
+
current_size = size
|
|
39
36
|
messages = []
|
|
40
37
|
closing do
|
|
41
38
|
q.subscribe(:ack => true) do |delivery_info, metadata, payload|
|
|
42
39
|
message = IncomingMessage.new(delivery_info, payload, channel)
|
|
43
40
|
messages << message
|
|
44
41
|
end
|
|
42
|
+
while messages.length < current_size
|
|
43
|
+
true
|
|
44
|
+
end
|
|
45
45
|
end
|
|
46
46
|
messages
|
|
47
47
|
end
|
|
@@ -51,20 +51,22 @@ module Superbolt
|
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
def peek
|
|
54
|
-
|
|
54
|
+
message = pop
|
|
55
|
+
push(message)
|
|
56
|
+
message
|
|
55
57
|
end
|
|
56
58
|
|
|
57
59
|
def pop
|
|
58
60
|
closing do
|
|
59
|
-
q.pop do |delivery_info, metadata,
|
|
60
|
-
message = IncomingMessage.new(delivery_info,
|
|
61
|
+
q.pop(ack: false) do |delivery_info, metadata, payload|
|
|
62
|
+
message = IncomingMessage.new(delivery_info, payload, channel) if payload
|
|
61
63
|
message && message.parse
|
|
62
64
|
end
|
|
63
65
|
end
|
|
64
66
|
end
|
|
65
67
|
|
|
66
68
|
delegate :slice, :[],
|
|
67
|
-
|
|
69
|
+
to: :all
|
|
68
70
|
|
|
69
71
|
def delete
|
|
70
72
|
messages = []
|
|
@@ -77,11 +79,11 @@ module Superbolt
|
|
|
77
79
|
message.ack
|
|
78
80
|
end
|
|
79
81
|
end
|
|
80
|
-
|
|
81
82
|
# channel is closed by block before message ack can complete
|
|
82
83
|
# therefore we must sleep :(
|
|
83
84
|
sleep 0.02
|
|
84
85
|
end
|
|
86
|
+
|
|
85
87
|
messages
|
|
86
88
|
end
|
|
87
89
|
end
|
data/lib/superbolt/version.rb
CHANGED
data/spec/connection_spec.rb
CHANGED
|
@@ -2,6 +2,7 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
describe Superbolt::Adapter::Bunny do
|
|
4
4
|
let(:connection) { Superbolt::Adapter::Bunny.new }
|
|
5
|
+
let(:channel) { connection.new_channel }
|
|
5
6
|
|
|
6
7
|
it "has an underlying open connection via Bunny" do
|
|
7
8
|
connection.socket.should be_a Bunny::Session
|
|
@@ -9,13 +10,15 @@ describe Superbolt::Adapter::Bunny do
|
|
|
9
10
|
connection.should be_open
|
|
10
11
|
end
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
describe 'new_channel' do
|
|
14
|
+
it "creates a channel" do
|
|
15
|
+
connection.new_channel.should be_a Bunny::Channel
|
|
16
|
+
end
|
|
14
17
|
end
|
|
15
18
|
|
|
16
19
|
it "delegates queue creation to the channel" do
|
|
17
|
-
queue =
|
|
20
|
+
queue = channel.queue('changelica')
|
|
18
21
|
queue.should be_a Bunny::Queue
|
|
19
|
-
|
|
22
|
+
channel.queues.keys.should include('changelica')
|
|
20
23
|
end
|
|
21
24
|
end
|
data/spec/queue_spec.rb
CHANGED
|
@@ -2,7 +2,6 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
describe 'Superbolt::Queue' do
|
|
4
4
|
let(:name) { 'superbolt_test' }
|
|
5
|
-
let(:connection) { Superbolt::Connection.new }
|
|
6
5
|
let(:queue) { Superbolt::Queue.new(name) }
|
|
7
6
|
let(:messages) { [] }
|
|
8
7
|
|
|
@@ -60,19 +59,15 @@ describe 'Superbolt::Queue' do
|
|
|
60
59
|
end
|
|
61
60
|
|
|
62
61
|
describe '#all' do
|
|
63
|
-
before do
|
|
62
|
+
before do
|
|
64
63
|
queue.push(message)
|
|
65
64
|
queue.push(message)
|
|
66
65
|
queue.push(message)
|
|
67
66
|
end
|
|
68
67
|
|
|
69
|
-
it "returns all the messages on the queue" do
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
messages.uniq.should == [decoded]
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
it "does not consume the messages" do
|
|
68
|
+
it "returns all the messages on the queue and doesnt consume them" do
|
|
69
|
+
Superbolt::IncomingMessage.should_receive(:new).exactly(3).times.and_return(double('whatever', parse:true))
|
|
70
|
+
queue.all
|
|
76
71
|
queue.size.should == 3
|
|
77
72
|
end
|
|
78
73
|
end
|
|
@@ -117,8 +112,8 @@ describe 'Superbolt::Queue' do
|
|
|
117
112
|
end
|
|
118
113
|
|
|
119
114
|
it "returns all messages where the block is true" do
|
|
120
|
-
messages = queue.delete{|json| json['i']
|
|
121
|
-
messages.map{|json| json['i']}.should == [3,
|
|
115
|
+
messages = queue.delete{|json| json['i'] % 2 != 0 }
|
|
116
|
+
messages.map{|json| json['i']}.should == [1,3,5,7,9]
|
|
122
117
|
end
|
|
123
118
|
|
|
124
119
|
it "removes those messages from the queue" do
|
data/superbolt.gemspec
CHANGED
|
@@ -19,10 +19,10 @@ Gem::Specification.new do |spec|
|
|
|
19
19
|
spec.require_paths = ["lib"]
|
|
20
20
|
|
|
21
21
|
spec.add_dependency "activesupport"
|
|
22
|
-
spec.add_dependency "
|
|
23
|
-
spec.add_dependency "bunny", "~> 0.9.0.rc1"
|
|
22
|
+
spec.add_dependency "bunny", "~> 1.0.5"
|
|
24
23
|
|
|
25
24
|
spec.add_development_dependency "bundler", "~> 1.3"
|
|
26
25
|
spec.add_development_dependency "rake"
|
|
27
26
|
spec.add_development_dependency "rspec"
|
|
27
|
+
spec.add_development_dependency "eventmachine"
|
|
28
28
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: superbolt
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- socialchorus
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2013-
|
|
11
|
+
date: 2013-12-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -24,34 +24,20 @@ dependencies:
|
|
|
24
24
|
- - '>='
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: '0'
|
|
27
|
-
- !ruby/object:Gem::Dependency
|
|
28
|
-
name: amqp
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - '>='
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: '0'
|
|
34
|
-
type: :runtime
|
|
35
|
-
prerelease: false
|
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
-
requirements:
|
|
38
|
-
- - '>='
|
|
39
|
-
- !ruby/object:Gem::Version
|
|
40
|
-
version: '0'
|
|
41
27
|
- !ruby/object:Gem::Dependency
|
|
42
28
|
name: bunny
|
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
|
44
30
|
requirements:
|
|
45
31
|
- - ~>
|
|
46
32
|
- !ruby/object:Gem::Version
|
|
47
|
-
version:
|
|
33
|
+
version: 1.0.5
|
|
48
34
|
type: :runtime
|
|
49
35
|
prerelease: false
|
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
37
|
requirements:
|
|
52
38
|
- - ~>
|
|
53
39
|
- !ruby/object:Gem::Version
|
|
54
|
-
version:
|
|
40
|
+
version: 1.0.5
|
|
55
41
|
- !ruby/object:Gem::Dependency
|
|
56
42
|
name: bundler
|
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -94,6 +80,20 @@ dependencies:
|
|
|
94
80
|
- - '>='
|
|
95
81
|
- !ruby/object:Gem::Version
|
|
96
82
|
version: '0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: eventmachine
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - '>='
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - '>='
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
97
97
|
description: Superbolt is comprised of a standalone app, and a queue-like queue for
|
|
98
98
|
sending messages between services and applications.
|
|
99
99
|
email:
|
|
@@ -108,7 +108,6 @@ files:
|
|
|
108
108
|
- README.md
|
|
109
109
|
- Rakefile
|
|
110
110
|
- lib/superbolt.rb
|
|
111
|
-
- lib/superbolt/adapter/amqp.rb
|
|
112
111
|
- lib/superbolt/adapter/base.rb
|
|
113
112
|
- lib/superbolt/adapter/bunny.rb
|
|
114
113
|
- lib/superbolt/app.rb
|
|
@@ -118,7 +117,6 @@ files:
|
|
|
118
117
|
- lib/superbolt/connection/queue.rb
|
|
119
118
|
- lib/superbolt/facade.rb
|
|
120
119
|
- lib/superbolt/incoming_message.rb
|
|
121
|
-
- lib/superbolt/message_ram.rb
|
|
122
120
|
- lib/superbolt/messenger.rb
|
|
123
121
|
- lib/superbolt/processor.rb
|
|
124
122
|
- lib/superbolt/queue.rb
|
|
@@ -127,7 +125,6 @@ files:
|
|
|
127
125
|
- spec/app_spec.rb
|
|
128
126
|
- spec/config_spec.rb
|
|
129
127
|
- spec/connection_spec.rb
|
|
130
|
-
- spec/message_ram_spec.rb
|
|
131
128
|
- spec/messenger_spec.rb
|
|
132
129
|
- spec/queue_spec.rb
|
|
133
130
|
- spec/spec_helper.rb
|
|
@@ -154,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
154
151
|
version: '0'
|
|
155
152
|
requirements: []
|
|
156
153
|
rubyforge_project:
|
|
157
|
-
rubygems_version: 2.
|
|
154
|
+
rubygems_version: 2.0.6
|
|
158
155
|
signing_key:
|
|
159
156
|
specification_version: 4
|
|
160
157
|
summary: Superbolt is a gem that makes SOA intra-app communication easy, via RabbitMQ
|
|
@@ -162,7 +159,6 @@ test_files:
|
|
|
162
159
|
- spec/app_spec.rb
|
|
163
160
|
- spec/config_spec.rb
|
|
164
161
|
- spec/connection_spec.rb
|
|
165
|
-
- spec/message_ram_spec.rb
|
|
166
162
|
- spec/messenger_spec.rb
|
|
167
163
|
- spec/queue_spec.rb
|
|
168
164
|
- spec/spec_helper.rb
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
module Superbolt
|
|
2
|
-
module Adapter
|
|
3
|
-
class AMQP < Base
|
|
4
|
-
def socket
|
|
5
|
-
@socket ||= ::AMQP.connect(config.connection_params)
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def channel
|
|
9
|
-
@channel ||= ::AMQP::Channel.new(socket)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def close(&block)
|
|
13
|
-
socket.close(&block)
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
@@ -1,31 +0,0 @@
|
|
|
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
|
data/spec/message_ram_spec.rb
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
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
|