mirror of
https://github.com/plashchynski/crono.git
synced 2026-06-11 17:32:45 +02:00
Fix crash when no jobs defined
This commit is contained in:
+9
-6
@@ -29,7 +29,11 @@ module Crono
|
|||||||
Cronotab.process(File.expand_path(config.cronotab))
|
Cronotab.process(File.expand_path(config.cronotab))
|
||||||
print_banner
|
print_banner
|
||||||
|
|
||||||
check_jobs
|
unless have_jobs?
|
||||||
|
logger.error "You have no jobs in you cronotab file #{config.cronotab}"
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if config.daemonize
|
if config.daemonize
|
||||||
start_working_loop_in_daemon
|
start_working_loop_in_daemon
|
||||||
else
|
else
|
||||||
@@ -39,6 +43,10 @@ module Crono
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def have_jobs?
|
||||||
|
Crono.scheduler.jobs.present?
|
||||||
|
end
|
||||||
|
|
||||||
def setup_log
|
def setup_log
|
||||||
if config.daemonize
|
if config.daemonize
|
||||||
self.logfile = config.logfile
|
self.logfile = config.logfile
|
||||||
@@ -85,11 +93,6 @@ module Crono
|
|||||||
::Rails.application.eager_load!
|
::Rails.application.eager_load!
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_jobs
|
|
||||||
return if Crono.scheduler.jobs.present?
|
|
||||||
logger.error "You have no jobs in you cronotab file #{config.cronotab}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def start_working_loop_in_daemon
|
def start_working_loop_in_daemon
|
||||||
unless ENV['RAILS_ENV'] == 'test'
|
unless ENV['RAILS_ENV'] == 'test'
|
||||||
begin
|
begin
|
||||||
|
|||||||
+4
-2
@@ -7,6 +7,7 @@ describe Crono::CLI do
|
|||||||
describe '#run' do
|
describe '#run' do
|
||||||
it 'should initialize rails with #load_rails and start working loop' do
|
it 'should initialize rails with #load_rails and start working loop' do
|
||||||
expect(cli).to receive(:load_rails)
|
expect(cli).to receive(:load_rails)
|
||||||
|
expect(cli).to receive(:have_jobs?).and_return(true)
|
||||||
expect(cli).to receive(:start_working_loop)
|
expect(cli).to receive(:start_working_loop)
|
||||||
expect(cli).to receive(:parse_options)
|
expect(cli).to receive(:parse_options)
|
||||||
expect(cli).to receive(:parse_command)
|
expect(cli).to receive(:parse_command)
|
||||||
@@ -14,12 +15,13 @@ describe Crono::CLI do
|
|||||||
expect(Crono::Cronotab).to receive(:process)
|
expect(Crono::Cronotab).to receive(:process)
|
||||||
cli.run
|
cli.run
|
||||||
end
|
end
|
||||||
context 'should run as daemon' do
|
|
||||||
|
|
||||||
before {cli.config.daemonize = true}
|
context 'should run as daemon' do
|
||||||
|
before { cli.config.daemonize = true }
|
||||||
|
|
||||||
it 'should initialize rails with #load_rails and start working loop' do
|
it 'should initialize rails with #load_rails and start working loop' do
|
||||||
expect(cli).to receive(:load_rails)
|
expect(cli).to receive(:load_rails)
|
||||||
|
expect(cli).to receive(:have_jobs?).and_return(true)
|
||||||
expect(cli).to receive(:start_working_loop_in_daemon)
|
expect(cli).to receive(:start_working_loop_in_daemon)
|
||||||
expect(cli).to receive(:parse_options)
|
expect(cli).to receive(:parse_options)
|
||||||
expect(cli).to receive(:parse_command)
|
expect(cli).to receive(:parse_command)
|
||||||
|
|||||||
Reference in New Issue
Block a user