queue_map 0.2 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/queue_map_consumer +0 -1
- data/lib/queue_map/consumer.rb +25 -7
- data/lib/queue_map/version.rb +1 -1
- data/lib/queue_map.rb +3 -2
- metadata +3 -3
data/bin/queue_map_consumer
CHANGED
data/lib/queue_map/consumer.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
class QueueMap::Consumer
|
2
2
|
attr_accessor :count_workers, :worker_proc, :on_exception_proc
|
3
3
|
attr_reader :name, :master_pid
|
4
|
-
attr_writer :pid_file
|
4
|
+
attr_writer :pid_file, :log_file
|
5
5
|
class Configurator
|
6
6
|
def initialize(base)
|
7
7
|
@base = base
|
@@ -14,6 +14,15 @@ class QueueMap::Consumer
|
|
14
14
|
def on_exception(&block); @base.on_exception_proc = block; end
|
15
15
|
def count_workers(value); @base.count_workers = value; end
|
16
16
|
def pid_file(value); @base.pid_file = value; end
|
17
|
+
def log_file(value); @base.log_file = value; end
|
18
|
+
|
19
|
+
def respond_to?(*args)
|
20
|
+
super || @base.respond_to?(*args)
|
21
|
+
end
|
22
|
+
|
23
|
+
def method_missing(method_name, *args)
|
24
|
+
@base.send(method_name, *args)
|
25
|
+
end
|
17
26
|
end
|
18
27
|
|
19
28
|
|
@@ -57,7 +66,15 @@ class QueueMap::Consumer
|
|
57
66
|
end
|
58
67
|
|
59
68
|
def pid_file
|
60
|
-
"#{name}_consumer.pid"
|
69
|
+
@pid_file ||= "#{name}_consumer.pid"
|
70
|
+
end
|
71
|
+
|
72
|
+
def log_file
|
73
|
+
@log_file ||= "#{name}_consumer.log"
|
74
|
+
end
|
75
|
+
|
76
|
+
def logger
|
77
|
+
@logger ||= Logger.new(log_file)
|
61
78
|
end
|
62
79
|
|
63
80
|
def start
|
@@ -84,8 +101,8 @@ class QueueMap::Consumer
|
|
84
101
|
if on_exception_proc
|
85
102
|
on_exception_proc.call(e)
|
86
103
|
else
|
87
|
-
|
88
|
-
|
104
|
+
logger.error e.message
|
105
|
+
logger.error e.backtrace
|
89
106
|
end
|
90
107
|
end
|
91
108
|
end
|
@@ -100,7 +117,7 @@ class QueueMap::Consumer
|
|
100
117
|
begin
|
101
118
|
run_consumer
|
102
119
|
rescue Exception => e
|
103
|
-
|
120
|
+
logger.error %(#{e}\n#{e.backtrace.join("\n")})
|
104
121
|
end
|
105
122
|
end)
|
106
123
|
end
|
@@ -136,6 +153,7 @@ class QueueMap::Consumer
|
|
136
153
|
Signal.trap("TERM") { stop(false) }
|
137
154
|
Signal.trap("INT") { stop }
|
138
155
|
after_fork_procs.each { |p| p.call }
|
156
|
+
logger.info "#{Process.pid}: running"
|
139
157
|
run_consumer
|
140
158
|
end
|
141
159
|
|
@@ -145,11 +163,11 @@ class QueueMap::Consumer
|
|
145
163
|
begin
|
146
164
|
Process.kill(graceful ? "INT" : "TERM", pid)
|
147
165
|
rescue Errno::ESRCH => e
|
148
|
-
|
166
|
+
logger.error "Unable to signal process #{pid}. Does the process not exist?"
|
149
167
|
end
|
150
168
|
end
|
151
169
|
|
152
|
-
|
170
|
+
logger.info "#{Process.pid}: stopping (graceful: #{graceful})"
|
153
171
|
if graceful
|
154
172
|
@shutting_down = true
|
155
173
|
else
|
data/lib/queue_map/version.rb
CHANGED
data/lib/queue_map.rb
CHANGED
@@ -6,9 +6,10 @@ module QueueMap
|
|
6
6
|
autoload :Consumer, File.dirname(__FILE__) + "/queue_map/consumer"
|
7
7
|
BUNNY_MUTEX = Mutex.new
|
8
8
|
extend self
|
9
|
-
attr_accessor :mode
|
9
|
+
attr_accessor :mode, :consumer_path
|
10
10
|
attr_writer :consumer_base_path
|
11
|
-
attr_accessor
|
11
|
+
attr_accessor
|
12
|
+
attr_reader :connection_info
|
12
13
|
|
13
14
|
DEFAULT_ON_TIMEOUT = lambda { |r| nil }
|
14
15
|
|
metadata
CHANGED