Class: ScheduleByIntervalJob

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
app/jobs/schedule_by_interval_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(options, one_by_one = false) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/jobs/schedule_by_interval_job.rb', line 6

def perform(options, one_by_one = false)

  # Run each Check separately (new ssh connection for each check even common host)
  if one_by_one
    MyNagios::Check.enabled.not_snoozed.where(interval: options['interval']).each do |check|
      MonitoringJob.perform_async(check)
    end

    return
  end

  # Optimized variant, group checks, run all necessary checks with one ssh connection
  MyNagios::Check.enabled.not_snoozed.where(interval: options['interval']).group_by{|check| { host: check.host, user: check.user, pem_key: check.pem_key } }.each do |config, checks|
    MonitoringJob.perform_async(checks.map(&:id), config)
  end
end