Class: ScoutAgent::Assignment::Status

Inherits:
ScoutAgent::Assignment show all
Defined in:
lib/scout_agent/assignment/status.rb

Overview

Invoke with:

scout_agent status

This command dumps the status database to $stdout. This data will show what processes are running, what they are currently working on, and when that status was last updated. It can be useful in tracking down issues with the agent to see where it went wrong.

Instance Attribute Summary

Attributes inherited from ScoutAgent::Assignment

#group, #other_args, #switches, #user

Instance Method Summary collapse

Methods inherited from ScoutAgent::Assignment

choose_group, choose_user, #initialize, plan, #prepare_and_execute

Methods included from Tracked

#clear_status, #force_status_database_reload, #status, #status_database, #status_log

Constructor Details

This class inherits a constructor from ScoutAgent::Assignment

Instance Method Details

#executeObject

Runs the status command.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/scout_agent/assignment/status.rb', line 18

def execute
  unless db = status_database
    abort_with_missing_db
  end
  
  puts "Status"
  puts "======"
  puts
  statuses = db.current_statuses
  if statuses.empty?
    puts "#{ScoutAgent.proper_agent_name} is not currently running."
  else
    puts "#{ScoutAgent.proper_agent_name} is running:"
    puts
    columns = [
      %w[Process       name],
      %w[PID           pid],
      %w[Current\ Task status],
      %w[Last\ Updated last_updated_at]
    ].map { |title, data| [title] + statuses.map { |row| row[data] } }
    sizes   = columns.map { |column| 
                column.map { |field| field.to_s.size }.max
              }
    format  = sizes.map { |size| "%-#{size}s" }.join(" ")
    puts format % columns.map { |column| column.first }
    puts format % sizes.map { |size| "-" * size }
    columns.first[1..-1].
            zip(*columns[1..-1].map { |c| c[1..-1] }) do |row|
      puts format % row
    end
  end
end