Module: Marty::BackgroundJob::FetchMissingInScheduleCronJobs

Defined in:
app/services/marty/background_job/fetch_missing_in_schedule_cron_jobs.rb

Class Method Summary collapse

Class Method Details

.callObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/services/marty/background_job/fetch_missing_in_schedule_cron_jobs.rb', line 4

def self.call
  in_dashboard = Marty::BackgroundJob::Schedule.all

  names_conditions = in_dashboard.map do |schedule|
    "%job_class: #{schedule.job_class}\n%"
  end

  djs = Delayed::Job.
    where.not(cron: nil).
    where.not(cron: '').
    where("handler ILIKE '%job_class:%'")

  djs.where.not('handler ILIKE ANY ( array[?] )', names_conditions).
    or(djs.where.not(schedule_id: in_dashboard.map(&:id)))
end