-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Crono::Cronotab to process cronotab
- Loading branch information
1 parent
8174f86
commit 1900a06
Showing
5 changed files
with
34 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Crono | ||
class Cronotab | ||
def self.process(cronotab_path = nil) | ||
cronotab_path ||= ENV['CRONOTAB'] || (defined?(Rails) && | ||
File.join(Rails.root, Config::CRONOTAB)) | ||
fail 'No cronotab defined' unless cronotab_path | ||
require cronotab_path | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,16 @@ | ||
module Crono | ||
def self.load_cronotab | ||
cronotab_path = ENV['CRONOTAB'] || (defined?(Rails) && | ||
File.join(Rails.root, Config::CRONOTAB)) | ||
fail 'No cronotab defined' unless cronotab_path | ||
puts "Load cronotab #{cronotab_path}" | ||
require cronotab_path | ||
end | ||
end | ||
|
||
namespace :crono do | ||
desc 'Clean unused job stats from DB' | ||
task clean: :environment do | ||
Crono.scheduler = Crono::Scheduler.new | ||
Crono.load_cronotab | ||
Crono::Cronotab.process | ||
current_job_ids = Crono.scheduler.jobs.map(&:job_id) | ||
Crono::CronoJob.where.not(job_id: current_job_ids).destroy_all | ||
end | ||
|
||
desc 'Check cronotab.rb syntax' | ||
task check: :environment do | ||
Crono.scheduler = Crono::Scheduler.new | ||
Crono.load_cronotab | ||
Crono::Cronotab.process | ||
puts 'Syntax ok' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'spec_helper' | ||
|
||
describe Crono::Cronotab do | ||
describe '#process' do | ||
it 'should load cronotab file' do | ||
cronotab_path = File.expand_path('../assets/good_cronotab.rb', __FILE__) | ||
expect(Crono.scheduler).to receive(:add_job).with(kind_of(Crono::Job)) | ||
expect { | ||
Crono::Cronotab.process(cronotab_path) | ||
}.to_not raise_error | ||
end | ||
|
||
it 'should raise error when cronotab is invalid' do | ||
cronotab_path = File.expand_path('../assets/bad_cronotab.rb', __FILE__) | ||
expect { | ||
Crono::Cronotab.process(cronotab_path) | ||
}.to raise_error | ||
end | ||
end | ||
end |