schedule and display only schedulable jobs

This commit is contained in:
Christophe Robillard 2022-07-21 15:49:02 +02:00
parent 0e3e6eb62a
commit 899047b656

View file

@ -1,15 +1,17 @@
namespace :jobs do
desc 'Schedule all cron jobs'
desc 'Schedule all schedulable cron jobs'
task schedule: :environment do
glob = Rails.root.join('app', 'jobs', '**', '*_job.rb')
Dir.glob(glob).each { |f| require f }
Cron::CronJob.subclasses.each(&:schedule)
schedulable_jobs.each(&:schedule)
end
desc 'Display schedule for all cron jobs'
desc 'Display schedule for all schedulable cron jobs'
task display_schedule: :environment do
schedulable_jobs.each(&:display_schedule)
end
def schedulable_jobs
glob = Rails.root.join('app', 'jobs', '**', '*_job.rb')
Dir.glob(glob).each { |f| require f }
Cron::CronJob.subclasses.each(&:display_schedule)
Cron::CronJob.subclasses.filter(&:schedulable?)
end
end