Class: Currentsh::Sidekiq
- Inherits:
-
Object
- Object
- Currentsh::Sidekiq
- Defined in:
- lib/currentsh/sidekiq.rb
Constant Summary collapse
- S =
::Sidekiq
Class Method Summary collapse
Instance Method Summary collapse
- #call(worker, msg, queue) ⇒ Object
- #error(context, error, start) ⇒ Object
- #start(context) ⇒ Object
- #stop(context, start) ⇒ Object
Class Method Details
.configure ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/currentsh/sidekiq.rb', line 77 def self.configure S.configure_server do |config| config.server_middleware do |chain| chain.insert_before S::Middleware::Server::Logging, self chain.remove S::Middleware::Server::Logging end end oldlogger = S::Logging.logger logger = Logger.new($stdout) logger.level = Logger::INFO logger.formatter = LogOutput.new S::Logging.logger = logger end |
Instance Method Details
#call(worker, msg, queue) ⇒ Object
3 4 5 6 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 |
# File 'lib/currentsh/sidekiq.rb', line 3 def call(worker, msg, queue) klass = msg['wrapped'] || worker.class.to_s jid = msg['jid'] context = { :class => klass, :jit => jid } if bid = msg['bid'] context[:bid] = bid end LogOutput.with_context(context) do begin ts = start context yield rescue StandardError => ex case ex when Interrupt, SystemExit, SignalException raise ex else error context, ex, ts raise ex end else stop context, ts end end end |
#error(context, error, start) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/currentsh/sidekiq.rb', line 50 def error(context, error, start) data = { time: Time.now, process: ::Process.pid, thread: Thread.current.object_id.to_s(36), event: "error", error: error.to_s, elapse: (Time.now - start) }.merge!(context) $stdout.puts "@current: #{JSON.generate(data)}" end |
#start(context) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/currentsh/sidekiq.rb', line 35 def start(context) time = Time.now data = { time: time, process: ::Process.pid, thread: Thread.current.object_id.to_s(36), event: "start", }.merge!(context) $stdout.puts "@current: #{JSON.generate(data)}" time end |
#stop(context, start) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/currentsh/sidekiq.rb', line 63 def stop(context, start) data = { time: Time.now, process: ::Process.pid, thread: Thread.current.object_id.to_s(36), event: "stop", elapse: (Time.now - start) }.merge!(context) $stdout.puts "@current: #{JSON.generate(data)}" end |