add schedulable? class method to cron jobs
This commit is contained in:
parent
bed6167010
commit
0e3e6eb62a
4 changed files with 30 additions and 0 deletions
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
|
7
spec/jobs/cron/cron_job_spec.rb
Normal file
7
spec/jobs/cron/cron_job_spec.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
RSpec.describe Cron::Datagouv::ExportAndPublishDemarchesPubliquesJob, type: :job do
|
||||
describe '#schedulable?' do
|
||||
it 'is schedulable by default' do
|
||||
expect(Cron::CronJob.schedulable?).to be_truthy
|
||||
end
|
||||
end
|
||||
end
|
|
@ -25,4 +25,19 @@ RSpec.describe Cron::Datagouv::ExportAndPublishDemarchesPubliquesJob, type: :job
|
|||
expect(Dir.glob("*demarches.json.gz", base: 'tmp').empty?).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
describe '#schedulable?' do
|
||||
context "when ENV['OPENDATA_ENABLED'] == 'enabled'" do
|
||||
it 'is schedulable' do
|
||||
ENV['OPENDATA_ENABLED'] = 'enabled'
|
||||
expect(Cron::Datagouv::ExportAndPublishDemarchesPubliquesJob.schedulable?).to be_truthy
|
||||
end
|
||||
end
|
||||
context "when ENV['OPENDATA_ENABLED'] != 'enabled'" do
|
||||
it 'is schedulable' do
|
||||
ENV['OPENDATA_ENABLED'] = nil
|
||||
expect(Cron::Datagouv::ExportAndPublishDemarchesPubliquesJob.schedulable?).to be_falsy
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue