class JobDispatch::Status
Attributes
socket[R]
Public Class Methods
new(connect_address)
click to toggle source
# File lib/job_dispatch/status.rb, line 9 def initialize(connect_address) @connect_address = connect_address end
Public Instance Methods
connect()
click to toggle source
# File lib/job_dispatch/status.rb, line 13 def connect if @socket.nil? @socket = JobDispatch.context.socket(ZMQ::REQ) @socket.connect(@connect_address) end end
disconnect()
click to toggle source
# File lib/job_dispatch/status.rb, line 20 def disconnect @socket.close @socket = nil end
fetch()
click to toggle source
# File lib/job_dispatch/status.rb, line 25 def fetch @socket.send(JSON.dump({command:'status'})) json = @socket.recv @status = JSON.parse(json).with_indifferent_access @time = Time.now end
print()
click to toggle source
# File lib/job_dispatch/status.rb, line 32 def print puts "Job Dispatcher status: #{@status[:status]} at #{@time}" puts "" table = Text::Table.new table.head = ['Queue', 'Worker ID', 'Worker Name', 'Status', 'Job ID', 'Job Details'] table.rows = [] @status[:queues].each do |queue, workers| if workers.empty? table.rows << [ queue, '- no workers -', '', '', '', '', ] else workers.each_pair do |worker_id, worker_status| job = worker_status[:job] if job params_str = if job[:parameters] job[:parameters].map(&:inspect).join(',')[0..20] else '' end job_details = "#{job[:target]}.#{job[:method]}(#{params_str})" end table.rows << [ queue, worker_id, worker_status[:name], worker_status[:status], worker_status[:job_id], job_details, ] end end end puts table.to_s end