philotic 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +13 -9
- data/examples/creating_named_queues/manually.rb +2 -2
- data/lib/philotic.rb +15 -9
- data/lib/philotic/config.rb +1 -1
- data/lib/philotic/logging/logger.rb +1 -1
- data/lib/philotic/routable.rb +4 -4
- data/lib/philotic/tasks/init_queues.rb +2 -2
- data/lib/philotic/version.rb +1 -1
- data/spec/philotic_spec.rb +30 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8aa3dc7a09929105b73c5fb51b7d0fe9bf73c111
|
4
|
+
data.tar.gz: c89f7608c819acb0cbca645ee3ace3b6936723a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee090366e13f093fcf493d5763e1c720fa6ca3fe524281380574010d6c347bc7326bd4462bc97d57c32aed9422e835506bad94290912bc9f8f7f4e92ae1fda94
|
7
|
+
data.tar.gz: 3f6de8f45b0af5cc06a9f304c4728e18be8c5f09a4f680d747b1add5575d78e77b718b23d7ed75ac34d56bb4d0ca78048289b82da55e18580340573d5d0fe963
|
data/.travis.yml
CHANGED
@@ -1,15 +1,19 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
- 1.9.3
|
4
|
+
- 2.0.0
|
5
|
+
- 2.1.0
|
6
|
+
- rbx-2.2.10
|
7
|
+
- jruby-19mode
|
8
|
+
- ruby-head
|
9
|
+
- jruby-head
|
10
10
|
script:
|
11
|
-
|
11
|
+
- bundle exec rspec
|
12
12
|
addons:
|
13
13
|
code_climate:
|
14
14
|
repo_token:
|
15
|
-
secure:
|
15
|
+
secure: D1HT1RpA+t8nZbXXD26rAyU8YJmaVFQXv+2yXmBmIca7d38zWz+SnJS8shtUXL48MRF31LC6ywTHjHi0JmCLKnwPQhddD8u8pecLGSOhc/wmdauDBTSlfYHo/2uErkVBix9oAgRvn/9b5sx7/yzq1PUWuhYgJhcnibECtQQQQkw=
|
16
|
+
notifications:
|
17
|
+
hipchat:
|
18
|
+
rooms:
|
19
|
+
secure: akLY832/pt0+9Y2TFKpzW08bagPMY//AcQJ5JGzc0yd3hZbXTlkW4S8bMEclBeHBqLGCV6vaWeN90PiYwIBs4IWlxopPAop4BEWeqRvD8+B4fxarXYwejt54vH3v4iCnHhSNBpFJDbykyfL0f0g9fhvM48eHzhBXTxPZfpQ9nXs=
|
@@ -5,8 +5,8 @@ $stdout.sync = true
|
|
5
5
|
require 'philotic'
|
6
6
|
|
7
7
|
# explicitly create named queues for this example
|
8
|
-
# ENV['
|
9
|
-
ENV['
|
8
|
+
# ENV['PHILOTIC_INITIALIZE_NAMED_QUEUE'] must equal 'true' to run Philotic.initialize_named_queue!
|
9
|
+
ENV['PHILOTIC_INITIALIZE_NAMED_QUEUE'] = 'true'
|
10
10
|
Philotic.initialize_named_queue!('male_queue', bindings: [{:'x-match' => 'all', gender: :M, available: true}])
|
11
11
|
Philotic.initialize_named_queue!('female_queue', bindings: [{:'x-match' => 'all', gender: :F, available: true}])
|
12
12
|
Philotic.initialize_named_queue!('test_queue', bindings: [{ :'x-match' => 'any', gender: :M, available: true }])
|
data/lib/philotic.rb
CHANGED
@@ -21,20 +21,26 @@ module Philotic
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def self.initialize_named_queue!(queue_name, config)
|
24
|
+
raise "ENV['PHILOTIC_INITIALIZE_NAMED_QUEUE'] must equal 'true' to run Philotic.initialize_named_queue!" unless ENV['PHILOTIC_INITIALIZE_NAMED_QUEUE'] == 'true'
|
25
|
+
|
24
26
|
Philotic.connect!
|
25
|
-
|
27
|
+
queue_exists = Philotic::Connection.connection.queue_exists? queue_name
|
26
28
|
|
27
|
-
|
29
|
+
should_delete_queue = queue_exists && ENV['PHILOTIC_DELETE_EXISTING_QUEUE'] == 'true'
|
30
|
+
should_create_queue = !queue_exists || ENV['PHILOTIC_DELETE_EXISTING_QUEUE'] == 'true'
|
28
31
|
|
29
|
-
if
|
32
|
+
if should_delete_queue
|
30
33
|
Philotic::Connection.channel.queue(queue_name, passive: true).delete
|
31
34
|
Philotic.logger.info "deleted old queue. queue: #{queue_name}"
|
32
35
|
end
|
33
36
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
37
|
+
if should_create_queue
|
38
|
+
config = config.deep_symbolize_keys
|
39
|
+
queue = queue_from_config(queue_name, config)
|
40
|
+
bind_queue(queue, config)
|
41
|
+
else
|
42
|
+
Philotic.logger.warn "Queue #{queue_name} not created; it already exists. ENV['PHILOTIC_DELETE_EXISTING_QUEUE'] must equal 'true' to override."
|
43
|
+
end
|
38
44
|
end
|
39
45
|
|
40
46
|
def self.bind_queue(queue, config)
|
@@ -85,8 +91,8 @@ module Philotic
|
|
85
91
|
Philotic::Connection.connected?
|
86
92
|
end
|
87
93
|
|
88
|
-
def self.connect!
|
89
|
-
Philotic::Connection.connect!
|
94
|
+
def self.connect!
|
95
|
+
Philotic::Connection.connect!
|
90
96
|
end
|
91
97
|
end
|
92
98
|
|
data/lib/philotic/config.rb
CHANGED
@@ -77,7 +77,7 @@ module Philotic
|
|
77
77
|
|
78
78
|
def message_return_handler
|
79
79
|
@message_return_handler ||= lambda do |basic_return, metadata, payload|
|
80
|
-
|
80
|
+
Philotic.logger.warn "Philotic message #{JSON.parse payload} was returned! reply_code = #{basic_return.reply_code}, reply_text = #{basic_return.reply_text} headers = #{metadata[:headers]}"
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
@@ -11,7 +11,7 @@ module Philotic
|
|
11
11
|
@event_class ||= Philotic::Logging::Event
|
12
12
|
end
|
13
13
|
|
14
|
-
def add(severity, message = nil, progname = nil
|
14
|
+
def add(severity, message = nil, progname = nil)
|
15
15
|
severity ||= UNKNOWN
|
16
16
|
if @logdev.nil? or severity < @level
|
17
17
|
return true
|
data/lib/philotic/routable.rb
CHANGED
@@ -62,8 +62,8 @@ module Philotic
|
|
62
62
|
attr_accessor(*names)
|
63
63
|
end
|
64
64
|
|
65
|
-
def publish(*args
|
66
|
-
self.new(*args).publish
|
65
|
+
def publish(*args)
|
66
|
+
self.new(*args).publish
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
@@ -88,8 +88,8 @@ module Philotic
|
|
88
88
|
@message_metadata.merge! options
|
89
89
|
end
|
90
90
|
|
91
|
-
def publish
|
92
|
-
Philotic::Publisher.publish
|
91
|
+
def publish
|
92
|
+
Philotic::Publisher.publish self
|
93
93
|
end
|
94
94
|
|
95
95
|
private
|
@@ -3,8 +3,8 @@ namespace :philotic do
|
|
3
3
|
task :init_queues, :filename do |t, args|
|
4
4
|
raise "You must specify a file name for #{t.name}: rake #{t.name}[FILENAME] #yes, you need the brackets, no space." if !args[:filename]
|
5
5
|
|
6
|
-
# ENV['
|
7
|
-
ENV['
|
6
|
+
# ENV['PHILOTIC_INITIALIZE_NAMED_QUEUE'] must equal 'true' to run Philotic.initialize_named_queue!
|
7
|
+
ENV['PHILOTIC_INITIALIZE_NAMED_QUEUE'] = 'true'
|
8
8
|
|
9
9
|
require 'philotic'
|
10
10
|
|
data/lib/philotic/version.rb
CHANGED
data/spec/philotic_spec.rb
CHANGED
@@ -24,17 +24,34 @@ describe Philotic do
|
|
24
24
|
}
|
25
25
|
}
|
26
26
|
end
|
27
|
-
it "should throw an error when ENV['
|
28
|
-
ENV['
|
29
|
-
queue_name
|
30
|
-
config
|
31
|
-
expect(Philotic).
|
32
|
-
expect { Philotic.initialize_named_queue! queue_name, config }.to raise_error("ENV['
|
27
|
+
it "should throw an error when ENV['PHILOTIC_INITIALIZE_NAMED_QUEUE'] is not set to 'true'" do
|
28
|
+
ENV['PHILOTIC_INITIALIZE_NAMED_QUEUE'] = nil
|
29
|
+
queue_name = test_queues.keys.first
|
30
|
+
config = test_queues[queue_name]
|
31
|
+
expect(Philotic).not_to receive(:connect!)
|
32
|
+
expect { Philotic.initialize_named_queue! queue_name, config }.to raise_error("ENV['PHILOTIC_INITIALIZE_NAMED_QUEUE'] must equal 'true' to run Philotic.initialize_named_queue!")
|
33
33
|
|
34
34
|
end
|
35
35
|
|
36
|
-
it
|
37
|
-
ENV['
|
36
|
+
it "should log a warning when ENV['PHILOTIC_DELETE_EXISTING_QUEUE'] is not set to 'true' and the queue already exists" do
|
37
|
+
ENV['PHILOTIC_INITIALIZE_NAMED_QUEUE'] = 'true'
|
38
|
+
test_queues.each_pair do |queue_name, config|
|
39
|
+
|
40
|
+
connection = double
|
41
|
+
|
42
|
+
expect(Philotic).to receive(:connect!)
|
43
|
+
expect(Philotic::Connection).to receive(:connection).and_return(connection)
|
44
|
+
expect(connection).to receive(:queue_exists?).and_return(true)
|
45
|
+
|
46
|
+
expect(Philotic.logger).to receive(:warn)
|
47
|
+
|
48
|
+
Philotic.initialize_named_queue! queue_name, config
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should delete the queue first when ENV['PHILOTIC_DELETE_EXISTING_QUEUE'] is set to 'true' and the queue already exists" do
|
53
|
+
ENV['PHILOTIC_INITIALIZE_NAMED_QUEUE'] = 'true'
|
54
|
+
ENV['PHILOTIC_DELETE_EXISTING_QUEUE'] = 'true'
|
38
55
|
|
39
56
|
test_queues.each_pair do |queue_name, config|
|
40
57
|
|
@@ -48,18 +65,18 @@ describe Philotic do
|
|
48
65
|
|
49
66
|
expect(Philotic).to receive(:connect!)
|
50
67
|
expect(Philotic::Connection).to receive(:connection).and_return(connection)
|
51
|
-
expect(connection).to receive(:queue_exists?)
|
52
|
-
expect(Philotic::Connection).to receive(:channel).and_return(channel).exactly(
|
68
|
+
expect(connection).to receive(:queue_exists?).and_return(true)
|
69
|
+
expect(Philotic::Connection).to receive(:channel).and_return(channel).exactly(3).times
|
70
|
+
expect(channel).to receive(:queue).with(queue_name, {passive: true}).and_return(queue)
|
71
|
+
expect(queue).to receive(:delete)
|
53
72
|
expect(channel).to receive(:queue).with(queue_name, queue_options).and_return(queue)
|
54
73
|
expect(channel).to receive(:headers).with(config[:exchange], durable: true) { exchange }
|
55
74
|
expect(queue).to receive(:name).and_return(queue_name).exactly(2).times
|
56
75
|
|
57
76
|
config[:bindings].each do |arguments|
|
58
77
|
expect(queue).to receive(:bind).with(exchange, {arguments: arguments})
|
59
|
-
Philotic.initialize_named_queue! queue_name, config
|
60
78
|
end
|
61
|
-
|
62
|
-
|
79
|
+
Philotic.initialize_named_queue! queue_name, config
|
63
80
|
end
|
64
81
|
end
|
65
82
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: philotic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Keyes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: codeclimate-test-reporter
|