class Sidekiq::Statistic::LogParser
Heroku have read only file system. See more in this link: devcenter.heroku.com/articles/read-only-filesystem
Constants
- WORKER_INFO_REGEXP_TEMPLATE
Attributes
jid_tag_regexp[R]
worker_info_regexp[R]
Public Class Methods
new(worker_name)
click to toggle source
# File lib/sidekiq/statistic/log_parser.rb, line 10 def initialize(worker_name) @worker_name = worker_name @logfile = log_file @worker_info_regexp = Regexp.compile(WORKER_INFO_REGEXP_TEMPLATE % { worker_name: @worker_name }) @jid_tag_regexp = Regexp.compile('(JID-[\\w]+)') end
Public Instance Methods
color(line)
click to toggle source
# File lib/sidekiq/statistic/log_parser.rb, line 46 def color(line) case when line.include?('done') then 'green' when line.include?('start') then 'yellow' when line.include?('fail') then 'red' end end
jid_style(worker_jid)
click to toggle source
# File lib/sidekiq/statistic/log_parser.rb, line 38 def jid_style(worker_jid) return unless worker_jid color = Digest::MD5.hexdigest(worker_jid)[4..9] .scan(/../).map{ |c| c.to_i(16) }.join ',' "style=\"background-color: rgba(#{color},0.2);\"" end
jid_tag(jid)
click to toggle source
# File lib/sidekiq/statistic/log_parser.rb, line 33 def jid_tag(jid) "<span class=\"statistic__jid js-jid__#{jid[4..-1]}\""\ "data-target=\".js-jid__#{jid[4..-1]}\" #{jid_style jid}>#{jid}</span>" end
parse()
click to toggle source
# File lib/sidekiq/statistic/log_parser.rb, line 17 def parse return [] unless File.exist?(@logfile) File .readlines(@logfile) .last(last_log_lines) .map{ |line| sub_line(line) if line.match(worker_info_regexp) } .compact end
sub_line(line)
click to toggle source
# File lib/sidekiq/statistic/log_parser.rb, line 27 def sub_line(line) line .sub(/\n/, '') .sub(jid_tag_regexp) { jid_tag($1) } end
Private Instance Methods
last_log_lines()
click to toggle source
# File lib/sidekiq/statistic/log_parser.rb, line 64 def last_log_lines Sidekiq::Statistic.configuration.last_log_lines end
log_file()
click to toggle source
# File lib/sidekiq/statistic/log_parser.rb, line 58 def log_file Sidekiq.options[:logfile] || Sidekiq.logger.instance_variable_get(:@logdev).filename || Sidekiq::Statistic.configuration.log_file end