Class: SolidQueueTui::Views::BlockedView

Inherits:
Object
  • Object
show all
Defined in:
lib/solid_queue_tui/views/blocked_view.rb

Instance Method Summary collapse

Constructor Details

#initialize(tui) ⇒ BlockedView

Returns a new instance of BlockedView.



6
7
8
9
10
11
12
# File 'lib/solid_queue_tui/views/blocked_view.rb', line 6

def initialize(tui)
  @tui = tui
  @table_state = RatatuiRuby::TableState.new(nil)
  @table_state.select(0)
  @selected_row = 0
  @jobs = []
end

Instance Method Details

#bindingsObject



75
76
77
78
79
80
81
# File 'lib/solid_queue_tui/views/blocked_view.rb', line 75

def bindings
  [
    { key: "j/k", action: "Navigate" },
    { key: "Enter", action: "Detail" },
    { key: "G/g", action: "Bottom/Top" }
  ]
end


83
# File 'lib/solid_queue_tui/views/blocked_view.rb', line 83

def breadcrumb = "blocked"

#handle_input(event) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/solid_queue_tui/views/blocked_view.rb', line 55

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



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
50
51
52
53
# File 'lib/solid_queue_tui/views/blocked_view.rb', line 20

def render(frame, area)
  columns = [
    { key: :id,              label: "ID",              width: 8 },
    { key: :queue_name,      label: "QUEUE",            width: 14 },
    { key: :class_name,      label: "CLASS",            width: :fill },
    { key: :priority,        label: "PRI",              width: 5 },
    { key: :concurrency_key, label: "CONCURRENCY KEY",  width: :fill },
    { key: :expires_at,      label: "EXPIRES AT",       width: 20 },
    { key: :blocked_since,   label: "BLOCKED SINCE",    width: 14 }
  ]

  rows = @jobs.map do |job|
    {
      id: job.id,
      queue_name: job.queue_name,
      class_name: job.class_name,
      priority: job.priority,
      concurrency_key: job.concurrency_key || "n/a",
      expires_at: format_time(job.expires_at),
      blocked_since: time_ago(job.created_at)
    }
  end

  table = Components::JobTable.new(
    @tui,
    title: "Blocked",
    columns: columns,
    rows: rows,
    selected_row: @selected_row,
    empty_message: "No blocked jobs"
  )

  table.render(frame, area, @table_state)
end

#selected_itemObject



70
71
72
73
# File 'lib/solid_queue_tui/views/blocked_view.rb', line 70

def selected_item
  return nil if @jobs.empty? || @selected_row >= @jobs.size
  @jobs[@selected_row]
end

#update(jobs:) ⇒ Object



14
15
16
17
18
# File 'lib/solid_queue_tui/views/blocked_view.rb', line 14

def update(jobs:)
  @jobs = jobs
  @selected_row = @selected_row.clamp(0, [@jobs.size - 1, 0].max)
  @table_state.select(@selected_row)
end