Module: Sidekiq::TUI::Tabs::SetTab

Includes:
Paginator, Filtering
Included in:
Dead, Retries, Scheduled
Defined in:
lib/sidekiq/tui/tabs/set_tab.rb

Constant Summary

Constants included from Paginator

Paginator::TYPE_CACHE

Instance Method Summary collapse

Methods included from Filtering

#append_to_filter, #current_filter, #filtering?, #on_filter_change, #remove_last_char_from_filter, #start_filtering, #stop_and_clear_filtering, #stop_filtering

Methods included from Paginator

#page, #page_items

Instance Method Details

#alter_rows!(action) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/sidekiq/tui/tabs/set_tab.rb', line 23

def alter_rows!(action)
  # log(to_s, @data[:selected])
  set = set_class.new
  each_selection do |id|
    score, jid = id.split("|")
    item = set.fetch(score, jid)&.first
    item&.send(action)
  end
end

#controlsObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/sidekiq/tui/tabs/set_tab.rb', line 12

def controls
  @controls ||= super + [{code: "D", modifiers: ["shift"], display: "D", description: "Delete",
                          action: ->(tui, tab) { tab.alter_rows!(:delete) }, refresh: true},
    {code: "R", modifiers: ["shift"], display: "R", description: "Retry",
     action: ->(tui, tab) { tab.alter_rows!(:retry) }, refresh: true},
    {code: "E", modifiers: ["shift"], display: "E", description: "Enqueue",
     action: ->(tui, tab) { tab.alter_rows!(:add_to_queue) }, refresh: true},
    {code: "K", modifiers: ["shift"], display: "K", description: "Kill",
     action: ->(tui, tab) { tab.alter_rows!(:kill) }, refresh: true}]
end

#featuresObject



8
9
10
# File 'lib/sidekiq/tui/tabs/set_tab.rb', line 8

def features
  %i[selectable pageable filterable]
end

#refresh_data_for_setObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/sidekiq/tui/tabs/set_tab.rb', line 33

def refresh_data_for_set
  set = set_class.new
  f = current_filter
  pager, rows, current, total = if f && f.size > 2
    rows = set.scan(f).to_a
    sz = rows.size
    [Sidekiq::TUI::PageOptions.new(1, sz), rows, 1, sz]
  else
    pager = @data.dig(:table, :pager) || Sidekiq::TUI::PageOptions.new(1, 25)
    current, total, items = page(set.name, pager.page, pager.size)
    rows = items.map { |msg, score| Sidekiq::SortedEntry.new(nil, score, msg) }
    [pager, rows, current, total]
  end

  @data.merge!(
    table: {pager:, rows:, current_page: current, total:,
            next_page: (current * pager.size < total) ? pager.page + 1 : nil,
            row_ids: rows.map { |job| [job.score, job["jid"]].join("|") }}
  )
end

#render(tui, frame, area) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/sidekiq/tui/tabs/set_tab.rb', line 54

def render(tui, frame, area)
  chunks = tui.layout_split(
    area,
    direction: :vertical,
    constraints: [
      tui.constraint_length(4), # Stats
      tui.constraint_fill(1)   # Table
    ]
  )

  render_stats_section(tui, frame, chunks[0])
  render_table(tui, frame, chunks[1]) do
    {
      title: t(name),
      header: ["☑️", "When", "Queue", "Job", "Arguments"].map { |x| t(x) },
      widths: [
        tui.constraint_length(5),
        tui.constraint_length(24),
        tui.constraint_length(20),
        tui.constraint_length(30),
        tui.constraint_fill(1)
      ]
    }.tap do |h|
      rows = @data[:table][:rows].map.with_index { |entry, idx|
        tui.table_row(
          cells: [
            selected?(entry) ? "" : "",
            entry.at,
            entry.queue,
            entry.display_class,
            entry.display_args
          ],
          style: idx.even? ? nil : tui.style(bg: :dark_gray)
        )
      }
      h[:rows] = rows
    end
  end
end