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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 75e1404b96bfb860814c48b3acf1380492c4f46b
4
- data.tar.gz: 86dd9ec5d5fe47f5d2a1831b62dde08f8cb2ec9a
3
+ metadata.gz: 8aa3dc7a09929105b73c5fb51b7d0fe9bf73c111
4
+ data.tar.gz: c89f7608c819acb0cbca645ee3ace3b6936723a7
5
5
  SHA512:
6
- metadata.gz: a64938a62e9dcc6ded5000577cd0dc97bd0b02722a81a60099375da3fd3a817b2c69521672df291f8243c1f8db442d909aaf8f15d4ffeae08cdd4a9ad4a9fc45
7
- data.tar.gz: fe5c070416b330cfce1dada9e9dc78d50c1cd2f9d68a9637c13338db50c8d5e05be970637d6fafd71f8c10e6e4366dbb343e016d455d89f3847c2cb6f058d850
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
- - 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
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
- - bundle exec rspec
11
+ - bundle exec rspec
12
12
  addons:
13
13
  code_climate:
14
14
  repo_token:
15
- secure: "D1HT1RpA+t8nZbXXD26rAyU8YJmaVFQXv+2yXmBmIca7d38zWz+SnJS8shtUXL48MRF31LC6ywTHjHi0JmCLKnwPQhddD8u8pecLGSOhc/wmdauDBTSlfYHo/2uErkVBix9oAgRvn/9b5sx7/yzq1PUWuhYgJhcnibECtQQQQkw="
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['INITIALIZE_NAMED_QUEUE'] must equal 'true' to run Philotic.initialize_named_queue!
9
- ENV['INITIALIZE_NAMED_QUEUE'] = 'true'
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
- config = config.deep_symbolize_keys
27
+ queue_exists = Philotic::Connection.connection.queue_exists? queue_name
26
28
 
27
- raise "ENV['INITIALIZE_NAMED_QUEUE'] must equal 'true' to run Philotic.initialize_named_queue!" unless ENV['INITIALIZE_NAMED_QUEUE'] == 'true'
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 Philotic::Connection.connection.queue_exists? queue_name
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
- queue = queue_from_config(queue_name, config)
35
-
36
- bind_queue(queue, config)
37
- yield queue if block_given?
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! &block
89
- Philotic::Connection.connect! &block
94
+ def self.connect!
95
+ Philotic::Connection.connect!
90
96
  end
91
97
  end
92
98
 
@@ -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
- puts "Philotic message #{JSON.parse payload} was returned! reply_code = #{basic_return.reply_code}, reply_text = #{basic_return.reply_text} headers = #{metadata[:headers]}"
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, &block)
14
+ def add(severity, message = nil, progname = nil)
15
15
  severity ||= UNKNOWN
16
16
  if @logdev.nil? or severity < @level
17
17
  return true
@@ -62,8 +62,8 @@ module Philotic
62
62
  attr_accessor(*names)
63
63
  end
64
64
 
65
- def publish(*args, &block)
66
- self.new(*args).publish(&block)
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 &block
92
- Philotic::Publisher.publish(self, &block)
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['INITIALIZE_NAMED_QUEUE'] must equal 'true' to run Philotic.initialize_named_queue!
7
- ENV['INITIALIZE_NAMED_QUEUE'] = 'true'
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
 
@@ -1,3 +1,3 @@
1
1
  module Philotic
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
@@ -24,17 +24,34 @@ describe Philotic do
24
24
  }
25
25
  }
26
26
  end
27
- it "should throw an error when ENV['INITIALIZE_NAMED_QUEUE'] is not set to 'true'" do
28
- ENV['INITIALIZE_NAMED_QUEUE'] = nil
29
- queue_name = test_queues.keys.first
30
- config = test_queues[queue_name]
31
- expect(Philotic).to receive(:connect!)
32
- expect { Philotic.initialize_named_queue! queue_name, config }.to raise_error("ENV['INITIALIZE_NAMED_QUEUE'] must equal 'true' to run Philotic.initialize_named_queue!")
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 'should set up the queue with the right parameters' do
37
- ENV['INITIALIZE_NAMED_QUEUE'] = 'true'
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(2).times
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.1
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-08 00:00:00.000000000 Z
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