demarches-normaliennes/lib/tasks/jobs.rake

20 lines
509 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2020-03-28 16:45:16 +01:00
namespace :jobs do
desc 'Schedule all schedulable cron jobs'
2020-03-28 16:45:16 +01:00
task schedule: :environment do
schedulable_jobs.each(&:schedule)
2020-03-28 16:45:16 +01:00
end
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.filter(&:schedulable?)
end
2020-03-28 16:45:16 +01:00
end