require_relative 'base_probe' module Roqua module Probes class MonitoringProbe extend BaseProbe def incomplete_jobs Roqua::Scheduling::CronJob.where('completed_at IS NULL OR completed_at < next_run_at') end def longest_delay_in_minutes delays = incomplete_jobs.pluck(:next_run_at).map do |next_run_at| Time.now - next_run_at end longest_delay_in_seconds = ([0] + delays).max (longest_delay_in_seconds / 1.minute).to_i end def call Appsignal.set_gauge('scheduler_delay_in_minutes', longest_delay_in_minutes) end end end end