Sha256: 8b1b9cbd98e672f8c528cd3845e64037fcca647653f94b8bdf3da83b2704f821
Contents?: true
Size: 1.06 KB
Versions: 1
Compression:
Stored size: 1.06 KB
Contents
module Sidekiq module Statistic # Heroku have read only file system. See more in this link: # https://devcenter.heroku.com/articles/read-only-filesystem class LogParser FILE_LINES_COUNT = 1_000 def initialize(worker_name) @worker_name = worker_name @logfile = log_file end def parse return [] unless File.exists?(@logfile) File .readlines(@logfile) .first(FILE_LINES_COUNT) .map{ |line| line_hash(line) if line[/\W?#@worker_name\W?/] } .compact end def line_hash(line) { color: color(line), text: line.sub(/\n/, '') } end def color(line) case when line.include?('done') then 'green' when line.include?('start') then 'yellow' when line.include?('fail') then 'red' end end private def log_file Sidekiq.options[:logfile] || Sidekiq.logger.instance_variable_get(:@logdev).filename || Sidekiq::Statistic.configuration.log_file end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sidekiq-statistic-1.0.0 | lib/sidekiq/statistic/log_parser.rb |