Class: Sidekiq::Cronitor::PeriodicJobs

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/cronitor/periodic_jobs.rb

Class Method Summary collapse

Class Method Details

.fetch_option(lop, key, default = nil) ⇒ Object



32
33
34
35
# File 'lib/sidekiq/cronitor/periodic_jobs.rb', line 32

def self.fetch_option(lop, key, default = nil)
  lop.options.fetch(key, default) ||
    lop.klass.constantize.sidekiq_options.fetch(key, default)
end

.sync_schedule!Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sidekiq/cronitor/periodic_jobs.rb', line 5

def self.sync_schedule!
  monitors_payload = []
  loops = Sidekiq::Periodic::LoopSet.new
  loops.each do |lop|
    if lop.options.has_key?('cronitor_enabled') || lop.klass.constantize.sidekiq_options.has_key?('cronitor_enabled')
      next unless fetch_option(lop, 'cronitor_enabled', Cronitor.auto_discover_sidekiq)
    else
      next if fetch_option(lop, 'cronitor_disabled', !Cronitor.auto_discover_sidekiq)
    end

    monitors_payload << {
      key: fetch_option(lop, 'cronitor_key') || lop.klass.to_s,
      group: fetch_option(lop, 'cronitor_group'),
      grace_seconds: fetch_option(lop, 'cronitor_grace_seconds')&.to_i,
      schedule: lop.schedule,
      timezone: lop.tz_name || Time.respond_to?(:zone) && Time.zone.tzinfo.name || nil,
      metadata: lop.options.to_s,
      platform: 'sidekiq',
      type: 'job'
    }.compact
  end

  Cronitor::Monitor.put(monitors: monitors_payload)
rescue Cronitor::Error => e
  Sidekiq.logger.error("[cronitor] error during #{name}.#{__method__}: #{e}")
end