rabbit_jobs 0.8.14 → 0.8.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/bunny +14 -5
- data/examples/bunny_server +3 -2
- data/examples/client +16 -6
- data/examples/worker +1 -1
- data/lib/rabbit_jobs.rb +0 -1
- data/lib/rabbit_jobs/main_loop.rb +1 -0
- data/lib/rabbit_jobs/publisher.rb +4 -13
- data/lib/rabbit_jobs/version.rb +1 -1
- data/lib/rabbit_jobs/worker.rb +3 -1
- data/rabbit_jobs.gemspec +1 -1
- metadata +4 -5
- data/lib/rabbit_jobs/amqp_helper.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a35a18641e303ebfd0d957c9b93cb632e7b24c2
|
4
|
+
data.tar.gz: ba95220f67bcb5cf0184e8b43561b2aa20b0c491
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 578beb9e51c8e2b4a6c6b4f021a6e67699c37aac28a1469618c6eb0fbcd802e708d259d02489c507fa07fa7234ae3c81381956f0d8156ea167fc4a81258c31bf
|
7
|
+
data.tar.gz: 2c2165684095c11649448a4bb573b18fd599a32680952249bb3b9b1a31b1408976b8469ec73b3f666e6ee341b2cc6fc85aec451ac2de9bf75fbde8c1ebf22696
|
data/examples/bunny
CHANGED
@@ -3,24 +3,33 @@
|
|
3
3
|
|
4
4
|
require 'bunny'
|
5
5
|
|
6
|
+
confirm = true
|
7
|
+
confirm = false
|
6
8
|
|
7
|
-
b = Bunny.new "amqp://localhost/bunny", heartbeat: 2
|
9
|
+
b = Bunny.new "amqp://localhost/bunny", heartbeat: 2, threaded: true, automatically_recover: true
|
8
10
|
b.start
|
9
11
|
channel = b.create_channel
|
10
|
-
# channel.confirm_select
|
12
|
+
# channel.confirm_select if confirm
|
11
13
|
exchange = channel.default_exchange
|
12
14
|
|
13
15
|
i = 0
|
14
16
|
loop do
|
15
|
-
puts "publishing hello #{i}"
|
17
|
+
# puts "publishing hello #{i}"
|
16
18
|
begin
|
17
|
-
|
18
|
-
#
|
19
|
+
# puts "connected? #{b.connected?.inspect}, status: #{b.status.inspect}"
|
20
|
+
puts "publishing #{i}"
|
21
|
+
if exchange.publish("hello #{i}", routing_key: "hello").channel.connection.connected?
|
22
|
+
puts "published #{i}"
|
23
|
+
else
|
24
|
+
puts "cannot publish #{i}"
|
25
|
+
end
|
26
|
+
# channel.wait_for_confirms if confirm
|
19
27
|
rescue Exception => e
|
20
28
|
puts e.message
|
21
29
|
puts e.backtrace.join("\r\n")
|
22
30
|
end
|
23
31
|
i += 1
|
32
|
+
puts
|
24
33
|
sleep 1
|
25
34
|
end
|
26
35
|
|
data/examples/bunny_server
CHANGED
@@ -9,9 +9,10 @@ require 'bunny'
|
|
9
9
|
# }
|
10
10
|
|
11
11
|
|
12
|
-
b = Bunny.new "amqp://localhost/bunny"
|
12
|
+
b = Bunny.new "amqp://localhost/bunny", heartbeat: 2, threaded: true, automatically_recover: true
|
13
13
|
b.start
|
14
14
|
channel = b.create_channel
|
15
|
+
channel.prefetch(1)
|
15
16
|
queue = channel.queue("hello", durable: true)
|
16
17
|
|
17
18
|
queue.subscribe do |delivery_info, properties, payload|
|
@@ -19,5 +20,5 @@ queue.subscribe do |delivery_info, properties, payload|
|
|
19
20
|
end
|
20
21
|
|
21
22
|
loop do
|
22
|
-
sleep 1
|
23
|
+
sleep 0.1
|
23
24
|
end
|
data/examples/client
CHANGED
@@ -7,28 +7,38 @@ require File.expand_path('../../lib/rabbit_jobs', __FILE__)
|
|
7
7
|
|
8
8
|
class MyCurrentJob
|
9
9
|
include RJ::Job
|
10
|
-
queue :
|
10
|
+
queue :mandarin
|
11
11
|
def perform(count)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
RJ.configure { |c|
|
16
|
-
c.queue "
|
16
|
+
c.queue "mandarin", durable: true, auto_delete: false, ack: true, arguments: {'x-ha-policy' => 'all'}
|
17
17
|
c.server "amqp://localhost/rj"
|
18
18
|
}
|
19
19
|
|
20
|
+
shutdown = false
|
21
|
+
trap('INT') do
|
22
|
+
shutdown = true
|
23
|
+
end
|
24
|
+
|
20
25
|
i = 0
|
21
26
|
loop do
|
22
27
|
puts "publishing job #{i}"
|
23
28
|
begin
|
24
|
-
# RJ.publish_to(:
|
29
|
+
# RJ.publish_to(:mandarin, MyCurrentJob, i)
|
25
30
|
MyCurrentJob.perform_async(i)
|
26
31
|
rescue Exception => e
|
27
|
-
# RJ::Publisher.amqp_connection.stop
|
28
32
|
puts e.message
|
29
33
|
puts e.backtrace.join("\r\n")
|
30
|
-
raise $!
|
31
34
|
end
|
35
|
+
|
36
|
+
if shutdown
|
37
|
+
puts "closing connection."
|
38
|
+
RJ::Publisher.send(:connection).stop
|
39
|
+
break
|
40
|
+
end
|
41
|
+
|
32
42
|
i += 1
|
33
43
|
sleep 1
|
34
|
-
end
|
44
|
+
end
|
data/examples/worker
CHANGED
data/lib/rabbit_jobs.rb
CHANGED
@@ -21,11 +21,12 @@ module RabbitJobs
|
|
21
21
|
|
22
22
|
def direct_publish_to(routing_key, payload, ex = {})
|
23
23
|
ex = {name: ex.to_s} unless ex.is_a?(Hash)
|
24
|
-
check_connection
|
25
24
|
begin
|
26
25
|
exchange_opts = Configuration::DEFAULT_MESSAGE_PARAMS.merge(ex || {})
|
27
26
|
exchange_name = exchange_opts.delete(:name).to_s
|
28
|
-
connection.default_channel.basic_publish(payload, exchange_name, routing_key, exchange_opts)
|
27
|
+
unless connection.default_channel.basic_publish(payload, exchange_name, routing_key, exchange_opts).connection.connected?
|
28
|
+
raise "Disconnected from #{RJ.config.server}. Connection status: #{connection.try(:status).inspect}"
|
29
|
+
end
|
29
30
|
rescue
|
30
31
|
RabbitJobs.logger.warn $!.message
|
31
32
|
RabbitJobs.logger.warn $!.backtrace.join("\n")
|
@@ -37,7 +38,6 @@ module RabbitJobs
|
|
37
38
|
|
38
39
|
def purge_queue(*routing_keys)
|
39
40
|
raise ArgumentError unless routing_keys.present?
|
40
|
-
check_connection
|
41
41
|
|
42
42
|
messages_count = 0
|
43
43
|
routing_keys.map(&:to_sym).each do |routing_key|
|
@@ -57,19 +57,10 @@ module RabbitJobs
|
|
57
57
|
|
58
58
|
def connection
|
59
59
|
unless settings[:connection]
|
60
|
-
settings[:connection] = Bunny.new(RabbitJobs.config.server
|
60
|
+
settings[:connection] = Bunny.new(RabbitJobs.config.server)
|
61
61
|
settings[:connection].start
|
62
|
-
# settings[:channel] = settings[:connection].create_channel
|
63
|
-
# settings[:channel].confirm_select
|
64
62
|
end
|
65
63
|
settings[:connection]
|
66
64
|
end
|
67
|
-
|
68
|
-
def check_connection
|
69
|
-
unless connection.connected?
|
70
|
-
connection.start if connection.status == :disconnected
|
71
|
-
raise "Disconnected from #{RJ.config.server}. Connection status: #{connection.try(:status).inspect}" unless connection.connected?
|
72
|
-
end
|
73
|
-
end
|
74
65
|
end
|
75
66
|
end
|
data/lib/rabbit_jobs/version.rb
CHANGED
data/lib/rabbit_jobs/worker.rb
CHANGED
@@ -13,7 +13,7 @@ module RabbitJobs
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def amqp_connection
|
16
|
-
Thread.current[:rj_worker_connection] ||=
|
16
|
+
Thread.current[:rj_worker_connection] ||= Bunny.new(RabbitJobs.config.server, automatically_recover: false).start
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.cleanup
|
@@ -113,7 +113,9 @@ module RabbitJobs
|
|
113
113
|
def consume_queue(amqp_channel, routing_key)
|
114
114
|
RJ.logger.info "Subscribing to #{routing_key}"
|
115
115
|
routing_key = routing_key.to_sym
|
116
|
+
|
116
117
|
queue = amqp_channel.queue(routing_key, queue_params(routing_key))
|
118
|
+
|
117
119
|
explicit_ack = !!queue_params(routing_key)[:ack]
|
118
120
|
|
119
121
|
queue.subscribe(ack: explicit_ack) do |delivery_info, properties, payload|
|
data/rabbit_jobs.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.require_paths = ["lib"]
|
17
17
|
gem.version = RabbitJobs::VERSION
|
18
18
|
|
19
|
-
gem.add_dependency "bunny", "0.9.
|
19
|
+
gem.add_dependency "bunny", "0.9.1"
|
20
20
|
gem.add_dependency "rake"
|
21
21
|
gem.add_dependency "rufus-scheduler", "~> 2.0"
|
22
22
|
gem.add_dependency "rails", "~> 3.2"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rabbit_jobs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Lazureykis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.9.
|
19
|
+
version: 0.9.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.9.
|
26
|
+
version: 0.9.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,7 +86,6 @@ files:
|
|
86
86
|
- examples/configuration.rb
|
87
87
|
- examples/worker
|
88
88
|
- lib/rabbit_jobs.rb
|
89
|
-
- lib/rabbit_jobs/amqp_helper.rb
|
90
89
|
- lib/rabbit_jobs/configuration.rb
|
91
90
|
- lib/rabbit_jobs/consumer/job_consumer.rb
|
92
91
|
- lib/rabbit_jobs/error_mailer.rb
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
|
3
|
-
module RabbitJobs
|
4
|
-
class AmqpHelper
|
5
|
-
|
6
|
-
class << self
|
7
|
-
|
8
|
-
def prepare_connection
|
9
|
-
conn = Bunny.new(RabbitJobs.config.server, :heartbeat_interval => 5)
|
10
|
-
conn.start unless conn.connected? || conn.connecting?
|
11
|
-
conn
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|