lib/good_job/cli.rb in good_job-0.2.1 vs lib/good_job/cli.rb in good_job-0.2.2

- old
+ new

@@ -6,14 +6,26 @@ desc :start, "Start jobs" def start require RAILS_ENVIRONMENT_RB - GoodJob::Scheduler.new + scheduler = GoodJob::Scheduler.new + %w[INT TERM].each do |signal| + trap(signal) { @stop_good_job_executable = true } + end + @stop_good_job_executable = false + + $stdout.puts "GoodJob waiting for jobs..." + Kernel.loop do - sleep 1 + sleep 0.1 + break if @stop_good_job_executable || scheduler.shutdown? end + + $stdout.puts "\nFinishing GoodJob's current jobs before exiting..." + scheduler.shutdown + $stdout.puts "GoodJob's jobs finished, exiting..." end default_task :start end end