Class: Workhorse::Jobs::DetectStaleJobsJob
- Inherits:
-
Object
- Object
- Workhorse::Jobs::DetectStaleJobsJob
- Defined in:
- lib/workhorse/jobs/detect_stale_jobs_job.rb
Instance Method Summary collapse
-
#initialize(locked_to_started_threshold: 3 * 60, run_time_threshold: 12 * 60) ⇒ DetectStaleJobsJob
constructor
Instantiates a new stale detection job.
- #perform ⇒ Object
Constructor Details
#initialize(locked_to_started_threshold: 3 * 60, run_time_threshold: 12 * 60) ⇒ DetectStaleJobsJob
Instantiates a new stale detection job.
11 12 13 14 |
# File 'lib/workhorse/jobs/detect_stale_jobs_job.rb', line 11 def initialize(locked_to_started_threshold: 3 * 60, run_time_threshold: 12 * 60) @locked_to_started_threshold = locked_to_started_threshold @run_time_threshold = run_time_threshold end |
Instance Method Details
#perform ⇒ Object
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 |
# File 'lib/workhorse/jobs/detect_stale_jobs_job.rb', line 16 def perform = [] # Detect jobs that are locked for too long # if @locked_to_started_threshold != 0 rel = Workhorse::DbJob.locked rel = rel.where('locked_at < ?', @locked_to_started_threshold.seconds.ago) ids = rel.pluck(:id) unless ids.empty? << "Detected #{ids.size} jobs that were locked more than "\ "#{@locked_to_started_threshold}s ago and might be stale: #{ids.inspect}." end end # Detect jobs that are running for too long # if @run_time_threshold != 0 rel = Workhorse::DbJob.started rel = rel.where('started_at < ?', @run_time_threshold.seconds.ago) ids = rel.pluck(:id) unless ids.empty? << "Detected #{ids.size} jobs that are running for longer than "\ "#{@run_time_threshold}s ago and might be stale: #{ids.inspect}." end end if .any? fail .join(' ') end end |