Sha256: 06dca43eefd2e3fb4f3a7f3d03419a1797d42ac8bb572c3041e668adb55634da

Contents?: true

Size: 1.55 KB

Versions: 4

Compression:

Stored size: 1.55 KB

Contents

#!/usr/bin/env ruby
#
# This command is expected to be run in the root of a Rails application which has a Job model class
# and has an initializer to configure JobDispatch.

ROOT_DIR = Dir.pwd
APP_PATH = File.expand_path('config/application.rb', ROOT_DIR)

unless File.exist?('config/job_dispatch.yml')
  $stderr.puts "Configuration file at 'config/job_dispatch.yml' not found."
  exit 1
end

if ENV['BUNDLE_GEMFILE'] || File.exists('Gemfile')
  require 'bundler/setup'
end

require 'job_dispatch'

# boot the rails app so we can access the Rails stored job queue.
require File.expand_path('config/boot.rb', ROOT_DIR)

ENV["RAILS_ENV"] ||= "development"
JobDispatch.load_config_from_yml('config/job_dispatch.yml', ENV["RAILS_ENV"])

$:.unshift(File.join(ROOT_DIR, "lib"))


require 'job_dispatch/status'
require 'json'

repeat = 0

if ARGV.count > 0
  repeat = ARGV.first.to_i
end

endpoint = JobDispatch.config.broker[:connect]
if endpoint.nil? || endpoint.empty?
  $stderr.puts "No Job Dispatch broker connect address has been specified."
  exit 1
end

status = JobDispatch::Status.new(endpoint)
status.connect
loop do
  begin
    Timeout.timeout(5) do
      status.fetch
      status.print
    end

    if repeat > 0
      sleep(repeat)
    else
      break
    end

  rescue TimeoutError
    # message may have been sent and we might be waiting for a reply that never comes, so
    # close socket and reconnect.
    puts "Job Dispatcher status: No response from broker, reconnecting..."
    status.disconnect
    status.connect
  rescue Interrupt
    exit 0
  end
end
status.disconnect

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
job_dispatch-0.2.0 bin/job-status
job_dispatch-0.1.0 bin/job-status
job_dispatch-0.0.2 bin/job-status
job_dispatch-0.0.1 bin/job-status