2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-03-28 16:45:16 +01:00
|
|
|
namespace :jobs do
|
2022-07-21 15:49:02 +02:00
|
|
|
desc 'Schedule all schedulable cron jobs'
|
2020-03-28 16:45:16 +01:00
|
|
|
task schedule: :environment do
|
2022-07-21 15:49:02 +02:00
|
|
|
schedulable_jobs.each(&:schedule)
|
2020-03-28 16:45:16 +01:00
|
|
|
end
|
2020-04-01 15:26:46 +02:00
|
|
|
|
2022-07-21 15:49:02 +02:00
|
|
|
desc 'Display schedule for all schedulable cron jobs'
|
2020-04-01 15:26:46 +02:00
|
|
|
task display_schedule: :environment do
|
2022-07-21 15:49:02 +02:00
|
|
|
schedulable_jobs.each(&:display_schedule)
|
|
|
|
end
|
|
|
|
|
|
|
|
def schedulable_jobs
|
2020-04-01 15:26:46 +02:00
|
|
|
glob = Rails.root.join('app', 'jobs', '**', '*_job.rb')
|
|
|
|
Dir.glob(glob).each { |f| require f }
|
2022-07-21 15:49:02 +02:00
|
|
|
Cron::CronJob.subclasses.filter(&:schedulable?)
|
2020-04-01 15:26:46 +02:00
|
|
|
end
|
2020-03-28 16:45:16 +01:00
|
|
|
end
|