rabbit_jobs 0.7.7 → 0.7.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -1
- data/build +8 -0
- data/examples/client +2 -1
- data/lib/rabbit_jobs/publisher.rb +15 -4
- data/lib/rabbit_jobs/version.rb +1 -1
- data/spec/integration/publisher_spec.rb +9 -4
- metadata +12 -11
data/Gemfile
CHANGED
data/build
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
abort("rspec tests failed.") unless system("COVERAGE=true && bundle exec rspec")
|
6
|
+
|
7
|
+
coverage_dir = File.expand_path('../coverage', __FILE__)
|
8
|
+
FileUtils.move(coverage_dir, ENV['CC_BUILD_ARTIFACTS']) if ENV['CC_BUILD_ARTIFACTS']
|
data/examples/client
CHANGED
@@ -22,9 +22,10 @@ loop do
|
|
22
22
|
begin
|
23
23
|
RJ.publish_to(:failover_test, MyCurrentJob, i)
|
24
24
|
rescue Exception => e
|
25
|
-
RJ::Publisher.amqp_connection.stop
|
25
|
+
# RJ::Publisher.amqp_connection.stop
|
26
26
|
puts e.message
|
27
27
|
puts e.backtrace.join("\r\n")
|
28
|
+
raise $!
|
28
29
|
end
|
29
30
|
i += 1
|
30
31
|
sleep 1
|
@@ -30,9 +30,11 @@ module RabbitJobs
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def direct_publish_to(routing_key, payload, ex = {})
|
33
|
+
check_connection
|
33
34
|
begin
|
34
35
|
exchange = get_exchange(ex)
|
35
36
|
exchange.publish(payload, Configuration::DEFAULT_MESSAGE_PARAMS.merge({key: routing_key.to_sym}))
|
37
|
+
# channel.wait_for_confirms
|
36
38
|
rescue
|
37
39
|
RJ.logger.warn $!.message
|
38
40
|
RJ.logger.warn $!.backtrace.join("\n")
|
@@ -52,7 +54,7 @@ module RabbitJobs
|
|
52
54
|
queue_name = RJ.config.queue_name(routing_key)
|
53
55
|
queue = connection.queue(queue_name, RJ.config[:queues][routing_key])
|
54
56
|
messages_count += queue.status[:message_count]
|
55
|
-
queue.
|
57
|
+
queue.purge
|
56
58
|
end
|
57
59
|
|
58
60
|
messages_count
|
@@ -65,7 +67,12 @@ module RabbitJobs
|
|
65
67
|
end
|
66
68
|
|
67
69
|
def connection
|
68
|
-
settings[:connection]
|
70
|
+
unless settings[:connection]
|
71
|
+
settings[:connection] = Bunny.new(RJ.config.server, :heartbeat_interval => 5)
|
72
|
+
settings[:connection].start
|
73
|
+
# settings[:channel].confirm_select
|
74
|
+
end
|
75
|
+
settings[:connection]
|
69
76
|
end
|
70
77
|
|
71
78
|
def exchanges
|
@@ -78,10 +85,14 @@ module RabbitJobs
|
|
78
85
|
|
79
86
|
if ex.size > 0
|
80
87
|
exchange_opts = Configuration::DEFAULT_EXCHANGE_PARAMS.merge(ex[:params] || {}).merge({type: (ex[:type] || :direct)})
|
81
|
-
exchanges[ex[:name]] ||= connection.
|
88
|
+
exchanges[ex[:name]] ||= connection.default_channel.exchange(ex[:name].to_s, exchange_opts)
|
82
89
|
else
|
83
|
-
exchanges[ex[:name]] ||= connection.
|
90
|
+
exchanges[ex[:name]] ||= connection.default_channel.default_exchange
|
84
91
|
end
|
85
92
|
end
|
93
|
+
|
94
|
+
def check_connection
|
95
|
+
raise unless connection.connected?
|
96
|
+
end
|
86
97
|
end
|
87
98
|
end
|
data/lib/rabbit_jobs/version.rb
CHANGED
@@ -7,7 +7,7 @@ describe RabbitJobs::Publisher do
|
|
7
7
|
|
8
8
|
before(:each) do
|
9
9
|
RabbitJobs.configure do |c|
|
10
|
-
c.server 'amqp://localhost/'
|
10
|
+
c.server 'amqp://localhost/rj'
|
11
11
|
c.queue 'rspec_queue'
|
12
12
|
c.queue 'rspec_queue2'
|
13
13
|
c.queue 'rspec_queue3'
|
@@ -17,12 +17,14 @@ describe RabbitJobs::Publisher do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'should publish message to queue' do
|
20
|
-
RJ.
|
20
|
+
RJ.publish_to(:rspec_queue, TestJob, 'some', 'other', 'params')
|
21
|
+
# sleep 0.1
|
21
22
|
RJ.purge_queue('rspec_queue').should == 1
|
22
23
|
end
|
23
24
|
|
24
25
|
it 'should accept symbol as queue name' do
|
25
26
|
RJ.publish_to(:rspec_queue, TestJob)
|
27
|
+
# sleep 0.1
|
26
28
|
RJ.purge_queue('rspec_queue').should == 1
|
27
29
|
end
|
28
30
|
|
@@ -30,23 +32,26 @@ describe RabbitJobs::Publisher do
|
|
30
32
|
RJ.publish_to(:rspec_queue, TestJob)
|
31
33
|
RJ.publish_to(:rspec_queue2, TestJob)
|
32
34
|
RJ.publish_to(:rspec_queue3, TestJob)
|
35
|
+
# sleep 0.1
|
33
36
|
RJ.purge_queue(:rspec_queue, :rspec_queue2, :rspec_queue3).should == 3
|
34
37
|
end
|
35
38
|
|
36
39
|
it 'should publish job with *params' do
|
37
40
|
RJ.publish_to(:rspec_queue, JobWithArgsArray, 'first value', :some_symbol, 123, 'and string')
|
41
|
+
# sleep 0.1
|
38
42
|
RJ.purge_queue(:rspec_queue).should == 1
|
39
43
|
end
|
40
44
|
|
41
45
|
it 'should publish 1000 messages in one second' do
|
42
|
-
count =
|
46
|
+
count = 100
|
43
47
|
published = 0
|
44
48
|
time = Benchmark.measure {
|
45
49
|
count.times {
|
46
50
|
RJ.publish_to(:rspec_queue, TestJob)
|
47
51
|
}
|
52
|
+
# sleep 0.1
|
48
53
|
removed = RJ.purge_queue(:rspec_queue, :rspec_queue2, :rspec_queue3)
|
49
|
-
removed.should ==
|
54
|
+
removed.should == 100
|
50
55
|
}
|
51
56
|
puts time
|
52
57
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rabbit_jobs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2013-03-22 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bunny
|
16
|
-
requirement: &
|
16
|
+
requirement: &9230940 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - =
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.9.0.pre8
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *9230940
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &9229700 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *9229700
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rufus-scheduler
|
38
|
-
requirement: &
|
38
|
+
requirement: &9349960 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '2.0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *9349960
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rails
|
49
|
-
requirement: &
|
49
|
+
requirement: &9697740 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '3.0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *9697740
|
58
58
|
description: Background jobs on RabbitMQ
|
59
59
|
email:
|
60
60
|
- lazureykis@gmail.com
|
@@ -68,6 +68,7 @@ files:
|
|
68
68
|
- LICENSE
|
69
69
|
- README.md
|
70
70
|
- Rakefile
|
71
|
+
- build
|
71
72
|
- examples/bunny
|
72
73
|
- examples/bunny_server
|
73
74
|
- examples/client
|
@@ -113,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
113
114
|
version: '0'
|
114
115
|
segments:
|
115
116
|
- 0
|
116
|
-
hash: -
|
117
|
+
hash: -1729098954943910884
|
117
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
119
|
none: false
|
119
120
|
requirements:
|
@@ -122,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
123
|
version: '0'
|
123
124
|
segments:
|
124
125
|
- 0
|
125
|
-
hash: -
|
126
|
+
hash: -1729098954943910884
|
126
127
|
requirements: []
|
127
128
|
rubyforge_project:
|
128
129
|
rubygems_version: 1.8.11
|