Class: SolidQueueTui::Views::ProcessesView
- Inherits:
-
Object
- Object
- SolidQueueTui::Views::ProcessesView
- Includes:
- FormattingHelpers
- Defined in:
- lib/solid_queue_tui/views/processes_view.rb
Constant Summary collapse
- KIND_COLORS =
{ "Worker" => :green, "Dispatcher" => :yellow, "Scheduler" => :blue }.freeze
Instance Method Summary collapse
- #bindings ⇒ Object
- #breadcrumb ⇒ Object
- #handle_input(event) ⇒ Object
-
#initialize(tui) ⇒ ProcessesView
constructor
A new instance of ProcessesView.
- #render(frame, area) ⇒ Object
- #selected_item ⇒ Object
- #update(processes:) ⇒ Object
Methods included from FormattingHelpers
#format_duration, #format_number, #format_time, #humanize_duration, #time_ago, #time_until, #truncate
Constructor Details
#initialize(tui) ⇒ ProcessesView
Returns a new instance of ProcessesView.
14 15 16 17 18 19 20 |
# File 'lib/solid_queue_tui/views/processes_view.rb', line 14 def initialize(tui) @tui = tui @table_state = RatatuiRuby::TableState.new(nil) @table_state.select(0) @selected_row = 0 @processes = [] end |
Instance Method Details
#bindings ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/solid_queue_tui/views/processes_view.rb', line 89 def bindings [ { key: "j/k", action: "Navigate" }, { key: "Enter", action: "Detail" }, { key: "G/g", action: "Bottom/Top" } ] end |
#breadcrumb ⇒ Object
97 |
# File 'lib/solid_queue_tui/views/processes_view.rb', line 97 def = "processes" |
#handle_input(event) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/solid_queue_tui/views/processes_view.rb', line 69 def handle_input(event) case event in { type: :key, code: "j" } | { type: :key, code: "up" } move_selection(-1) in { type: :key, code: "k" } | { type: :key, code: "down" } move_selection(1) in { type: :key, code: "g" } jump_to_top in { type: :key, code: "G" } jump_to_bottom else nil end end |
#render(frame, area) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/solid_queue_tui/views/processes_view.rb', line 28 def render(frame, area) columns = [ { key: :id, label: "ID", width: 6 }, { key: :kind, label: "KIND", width: 12 }, { key: :hostname, label: "HOSTNAME", width: :fill }, { key: :pid, label: "PID", width: 8 }, { key: :name, label: "NAME", width: :fill }, { key: :queues, label: "QUEUES", width: :fill }, { key: :heartbeat, label: "HEARTBEAT", width: 12 }, { key: :uptime, label: "UPTIME", width: 10 }, { key: :status, label: "STATUS", width: 8 } ] rows = @processes.map do |proc| alive = proc.alive? { id: proc.id, kind: proc.kind, hostname: proc.hostname || "n/a", pid: proc.pid, name: proc.name || "n/a", queues: Array(proc.queues).join(", "), heartbeat: time_ago(proc.last_heartbeat_at), uptime: format_duration(proc.uptime), status: alive ? "alive" : "dead" } end table = Components::JobTable.new( @tui, title: "Processes", columns: columns, rows: rows, selected_row: @selected_row, empty_message: "No active processes — is Solid Queue running?" ) table.render(frame, area, @table_state) end |
#selected_item ⇒ Object
84 85 86 87 |
# File 'lib/solid_queue_tui/views/processes_view.rb', line 84 def selected_item return nil if @processes.empty? || @selected_row >= @processes.size @processes[@selected_row] end |
#update(processes:) ⇒ Object
22 23 24 25 26 |
# File 'lib/solid_queue_tui/views/processes_view.rb', line 22 def update(processes:) @processes = processes @selected_row = @selected_row.clamp(0, [@processes.size - 1, 0].max) @table_state.select(@selected_row) end |