7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/applicaster/sidekiq/middleware.rb', line 7
def call(worker, item, queue)
::Sidekiq::Logging.with_context("#{worker.class.to_s} JID-#{item['jid']}") do
begin
logger.info(filter_fields({
message: "Start: #{worker.class.to_s} JID-#{item['jid']}",
jid: item['jid'],
pid: pid,
tid: tid,
context: context,
worker: worker.class.to_s,
queue: queue,
args: item['args'].inspect,
latency: ::Sidekiq::Job.new(::Sidekiq.dump_json(item)).latency,
memory: memory
}))
start = Time.now
yield
logger.info(filter_fields({
message: "Done: #{worker.class.to_s} JID-#{item['jid']}",
jid: item['jid'],
pid: pid,
tid: tid,
context: context,
worker: worker.class.to_s,
queue: queue,
args: item['args'].inspect,
runtime: elapsed(start),
memory: memory
}))
rescue Exception => e
logger.error(filter_fields({
message: "Fail: #{worker.class.to_s} JID-#{item['jid']}",
jid: item['jid'],
pid: pid,
tid: tid,
context: context,
worker: worker.class.to_s,
queue: queue,
args: item['args'].inspect,
runtime: elapsed(start),
exception_class: e.class.to_s,
exception_message: e.message,
backtrace: e.backtrace.join("\n"),
memory: memory
}))
raise e
end
end
end
|