rabbit_jobs 0.2.0.pre1 → 0.2.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rabbit_jobs/amqp_helper.rb +14 -10
- data/lib/rabbit_jobs/scheduler.rb +4 -8
- data/lib/rabbit_jobs/version.rb +1 -1
- metadata +2 -2
@@ -14,6 +14,7 @@ module RabbitJobs
|
|
14
14
|
yield false
|
15
15
|
else
|
16
16
|
AMQP.start(RJ.config.url) {
|
17
|
+
AmqpHelper.init_auto_recovery
|
17
18
|
yield true
|
18
19
|
}
|
19
20
|
end
|
@@ -29,6 +30,19 @@ module RabbitJobs
|
|
29
30
|
|
30
31
|
private
|
31
32
|
|
33
|
+
def init_auto_recovery
|
34
|
+
AMQP.connection.on_recovery do |conn, opts|
|
35
|
+
url = url_from_opts opts
|
36
|
+
RJ.logger.warn "[network failure] Connection to #{url} established."
|
37
|
+
end
|
38
|
+
|
39
|
+
AMQP.connection.on_tcp_connection_loss do |conn, opts|
|
40
|
+
url = url_from_opts opts
|
41
|
+
RJ.logger.warn "[network failure] Trying to reconnect to #{url}..."
|
42
|
+
conn.reconnect(false, 2)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
32
46
|
def url_from_opts(opts = {})
|
33
47
|
s = ""
|
34
48
|
s << opts[:scheme]
|
@@ -41,16 +55,6 @@ module RabbitJobs
|
|
41
55
|
|
42
56
|
def create_channel
|
43
57
|
AMQP.channel = AMQP::Channel.new(AMQP.connection, auto_recovery: true)
|
44
|
-
|
45
|
-
AMQP.connection.on_recovery do |conn, opts|
|
46
|
-
url = url_from_opts opts
|
47
|
-
RJ.logger.warn "[network failure] Connection to #{url} established."
|
48
|
-
end
|
49
|
-
AMQP.connection.on_tcp_connection_loss do |conn, opts|
|
50
|
-
url = url_from_opts opts
|
51
|
-
RJ.logger.warn "[network failure] Trying to reconnect to #{url}..."
|
52
|
-
conn.reconnect(false, 2)
|
53
|
-
end
|
54
58
|
end
|
55
59
|
end
|
56
60
|
end
|
@@ -66,6 +66,7 @@ module RabbitJobs
|
|
66
66
|
RJ.publish_to(queue, klass_name, *params)
|
67
67
|
rescue
|
68
68
|
RJ.logger.warn "Failed to publish #{klass_name}:\n #{$!}\n params = #{params.inspect}"
|
69
|
+
RJ.logger.warn $!.inspect
|
69
70
|
end
|
70
71
|
|
71
72
|
def rufus_scheduler
|
@@ -87,19 +88,14 @@ module RabbitJobs
|
|
87
88
|
$0 = self.process_name || "rj_scheduler"
|
88
89
|
|
89
90
|
processed_count = 0
|
90
|
-
AmqpHelper.with_amqp do |
|
91
|
-
|
92
|
-
|
93
|
-
channel.on_error do |ch, channel_close|
|
94
|
-
puts "Channel-level error: #{channel_close.reply_text}, shutting down..."
|
95
|
-
connection.disconnect { EM.stop }
|
96
|
-
end
|
91
|
+
AmqpHelper.with_amqp do |stop_em|
|
92
|
+
AmqpHelper.prepare_channel
|
97
93
|
|
98
94
|
load_schedule!
|
99
95
|
|
100
96
|
check_shutdown = Proc.new {
|
101
97
|
if @shutdown
|
102
|
-
connection.
|
98
|
+
AMQP::connection.disconnect {
|
103
99
|
File.delete(self.pidfile) if self.pidfile
|
104
100
|
EM.stop { exit! }
|
105
101
|
}
|
data/lib/rabbit_jobs/version.rb
CHANGED
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.2.0.
|
4
|
+
version: 0.2.0.pre2
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -113,7 +113,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
113
113
|
version: '0'
|
114
114
|
segments:
|
115
115
|
- 0
|
116
|
-
hash:
|
116
|
+
hash: 1731730238490363381
|
117
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
118
|
none: false
|
119
119
|
requirements:
|