Sha256: 69ac4740610ba7dff2d6276c885cd82669ba22d44326361967136e3e4be8f180

Contents?: true

Size: 752 Bytes

Versions: 1

Compression:

Stored size: 752 Bytes

Contents

require 'thor'

module GoodJob
  class CLI < Thor
    RAILS_ENVIRONMENT_RB = File.expand_path("config/environment.rb")

    desc :start, "Start jobs"
    def start
      require RAILS_ENVIRONMENT_RB

      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 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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
good_job-0.2.2 lib/good_job/cli.rb