add schedulable? class method to cron jobs

This commit is contained in:
Christophe Robillard 2022-07-21 15:28:28 +02:00
parent bed6167010
commit 0e3e6eb62a
4 changed files with 30 additions and 0 deletions

View file

@ -3,6 +3,10 @@ class Cron::CronJob < ApplicationJob
class_attribute :schedule_expression
class << self
def schedulable?
true
end
def schedule
remove if cron_expression_changed?
set(cron: cron_expression).perform_later if !scheduled?

View file

@ -15,4 +15,8 @@ class Cron::Datagouv::ExportAndPublishDemarchesPubliquesJob < Cron::CronJob
FileUtils.rm(gzip_filepath)
end
end
def self.schedulable?
ENV.fetch('OPENDATA_ENABLED', nil) == 'enabled'
end
end