message 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/message.rb +4 -0
- data/lib/message/filters/benchmarking.rb +2 -2
- data/lib/message/filters/error_handling.rb +1 -1
- data/lib/message/worker.rb +4 -7
- metadata +1 -1
data/lib/message.rb
CHANGED
@@ -7,11 +7,11 @@ module Message
|
|
7
7
|
return filter.call(msg) unless action == :process
|
8
8
|
|
9
9
|
ret = nil
|
10
|
-
Message.
|
10
|
+
Message.log(:info) { "#{job.name}: processing one message"}
|
11
11
|
s = Benchmark.realtime do
|
12
12
|
ret = filter.call(msg)
|
13
13
|
end
|
14
|
-
Message.
|
14
|
+
Message.log(:info) { "#{job.name}: processed in #{(1000 * s).to_i}ms" }
|
15
15
|
ret
|
16
16
|
end
|
17
17
|
end
|
@@ -9,7 +9,7 @@ module Message
|
|
9
9
|
filter.call(msg)
|
10
10
|
rescue => e
|
11
11
|
job_name = job.name rescue 'unknown job(find job name failed)'
|
12
|
-
Message.
|
12
|
+
Message.log(:error) {"#{action} #{job_name} message failed, #{e.class}: #{e.message}\n#{e.backtrace.join("\n")}"}
|
13
13
|
if self.callback
|
14
14
|
self.callback.call(e, msg, job, action)
|
15
15
|
end
|
data/lib/message/worker.rb
CHANGED
@@ -71,15 +71,16 @@ module Message
|
|
71
71
|
delay = options[:delay] || 10 + rand(20)
|
72
72
|
Thread.start do
|
73
73
|
begin
|
74
|
-
log(:info) { "start" }
|
74
|
+
Message.log(:info) { "[Worker] start in #{delay}" }
|
75
75
|
sleep delay
|
76
76
|
loop do
|
77
77
|
process(size)
|
78
78
|
sleep interval
|
79
79
|
end
|
80
|
-
log(:info) { "stopped" }
|
81
80
|
rescue => e
|
82
|
-
log(:error) { "crashed: #{e.message}\n#{e.backtrace.join("\n")}"}
|
81
|
+
Message.log(:error) { "[Worker] crashed: #{e.message}\n#{e.backtrace.join("\n")}"}
|
82
|
+
ensure
|
83
|
+
Message.log(:info) { "[Worker] stopped" }
|
83
84
|
end
|
84
85
|
end
|
85
86
|
end
|
@@ -112,9 +113,5 @@ module Message
|
|
112
113
|
obj, m, args = work
|
113
114
|
obj.send(m, *args)
|
114
115
|
end
|
115
|
-
|
116
|
-
def log(level, &block)
|
117
|
-
Message.logger.send(level) { "[Worker(#{Thread.current.object_id})] #{block.call}" }
|
118
|
-
end
|
119
116
|
end
|
120
117
|
end
|