class Resque::Plugins::JobHistory::HistoryDetails

A base class for job history classes which provides a base key and a few common functions.

Constants

MAX_LINEAR_HISTORY
NAME_SPACE

Attributes

class_name[RW]

Public Class Methods

class_list_page_size() click to toggle source
# File lib/resque/plugins/job_history/history_details.rb, line 23
def class_list_page_size
  @class_list_page_size ||= Resque::Plugins::JobHistory::PAGE_SIZE
end
class_list_page_size=(value) click to toggle source
# File lib/resque/plugins/job_history/history_details.rb, line 18
def class_list_page_size=(value)
  @class_list_page_size = value
  @class_list_page_size = 1 if @class_list_page_size < 1
end
job_history_key() click to toggle source
# File lib/resque/plugins/job_history/history_details.rb, line 14
def job_history_key
  "job_history"
end
linear_page_size() click to toggle source
# File lib/resque/plugins/job_history/history_details.rb, line 32
def linear_page_size
  @linear_page_size ||= Resque::Plugins::JobHistory::PAGE_SIZE
end
linear_page_size=(value) click to toggle source
# File lib/resque/plugins/job_history/history_details.rb, line 27
def linear_page_size=(value)
  @linear_page_size = value
  @linear_page_size = 1 if @linear_page_size < 1
end
max_linear_jobs() click to toggle source
# File lib/resque/plugins/job_history/history_details.rb, line 36
def max_linear_jobs
  @max_linear_jobs ||= MAX_LINEAR_HISTORY
end
max_linear_jobs=(value) click to toggle source
# File lib/resque/plugins/job_history/history_details.rb, line 40
def max_linear_jobs=(value)
  @max_linear_jobs = value

  return unless @max_linear_jobs.present?

  @max_linear_jobs = @max_linear_jobs.to_i
  @max_linear_jobs = nil if @max_linear_jobs.negative?
end
new(class_name) click to toggle source
# File lib/resque/plugins/job_history/history_details.rb, line 50
def initialize(class_name)
  @class_name = class_name
end

Public Instance Methods

class_name_valid?() click to toggle source
# File lib/resque/plugins/job_history/history_details.rb, line 98
def class_name_valid?
  described_class.present?
end
clean_old_running_jobs() click to toggle source
# File lib/resque/plugins/job_history/history_details.rb, line 106
def clean_old_running_jobs
  too_old_time = class_purge_age.ago

  running_jobs.jobs.each do |job|
    job_start = job.start_time

    if job_start.present? && job_start.to_time < too_old_time
      job.cancel " Job timed out."
    end
  end
end
finished_jobs() click to toggle source
# File lib/resque/plugins/job_history/history_details.rb, line 66
def finished_jobs
  @finished_list ||= HistoryList.new(class_name, "finished")
end
job_history_base_key() click to toggle source
# File lib/resque/plugins/job_history/history_details.rb, line 58
def job_history_base_key
  "#{Resque::Plugins::JobHistory::HistoryDetails.job_history_key}.#{class_name}"
end
last_run() click to toggle source
# File lib/resque/plugins/job_history/history_details.rb, line 102
def last_run
  running_jobs.latest_job || finished_jobs.latest_job
end
linear_jobs() click to toggle source
# File lib/resque/plugins/job_history/history_details.rb, line 70
def linear_jobs
  @linear_list ||= HistoryList.new("", "linear", Resque::Plugins::JobHistory::HistoryDetails.max_linear_jobs)
end
max_concurrent_jobs() click to toggle source
# File lib/resque/plugins/job_history/history_details.rb, line 74
def max_concurrent_jobs
  redis.get(max_running_key).to_i
end
num_finished_jobs() click to toggle source
# File lib/resque/plugins/job_history/history_details.rb, line 86
def num_finished_jobs
  finished_jobs.num_jobs
end
num_running_jobs() click to toggle source
# File lib/resque/plugins/job_history/history_details.rb, line 82
def num_running_jobs
  running_jobs.num_jobs
end
page_size() click to toggle source
# File lib/resque/plugins/job_history/history_details.rb, line 118
def page_size
  class_page_size
end
redis() click to toggle source
# File lib/resque/plugins/job_history/history_details.rb, line 54
def redis
  @redis ||= Redis::Namespace.new(NAME_SPACE, redis: Resque.redis)
end
running_jobs() click to toggle source
# File lib/resque/plugins/job_history/history_details.rb, line 62
def running_jobs
  @running_list ||= HistoryList.new(class_name, "running")
end
total_failed_jobs() click to toggle source
# File lib/resque/plugins/job_history/history_details.rb, line 78
def total_failed_jobs
  redis.get(total_failed_key).to_i
end
total_finished_jobs() click to toggle source
# File lib/resque/plugins/job_history/history_details.rb, line 94
def total_finished_jobs
  finished_jobs.total
end
total_run_jobs() click to toggle source
# File lib/resque/plugins/job_history/history_details.rb, line 90
def total_run_jobs
  running_jobs.total
end

Private Instance Methods

class_exclude_from_linear_history() click to toggle source
# File lib/resque/plugins/job_history/history_details.rb, line 136
def class_exclude_from_linear_history
  described_class.try(:exclude_from_linear_history) || false
end
class_history_len() click to toggle source
# File lib/resque/plugins/job_history/history_details.rb, line 140
def class_history_len
  hist_len = described_class.try(:job_history_len) || MAX_JOB_HISTORY
  hist_len.negative? ? 0 : hist_len
end
class_page_size() click to toggle source
# File lib/resque/plugins/job_history/history_details.rb, line 145
def class_page_size
  pg_size = described_class.try(:page_size) || Resque::Plugins::JobHistory::PAGE_SIZE
  pg_size < 1 ? 1 : pg_size
end
class_purge_age() click to toggle source
# File lib/resque/plugins/job_history/history_details.rb, line 132
def class_purge_age
  described_class.try(:purge_age) || 24.hours
end
described_class() click to toggle source
# File lib/resque/plugins/job_history/history_details.rb, line 124
def described_class
  return if class_name.blank?

  class_name.constantize
rescue StandardError
  nil
end
max_running_key() click to toggle source
# File lib/resque/plugins/job_history/history_details.rb, line 154
def max_running_key
  "#{job_history_base_key}.max_jobs"
end
total_failed_key() click to toggle source
# File lib/resque/plugins/job_history/history_details.rb, line 150
def total_failed_key
  "#{job_history_base_key}.total_failed"
end