sidekiq 8.1.1 → 8.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/Changes.md +49 -2
  3. data/README.md +1 -1
  4. data/bin/kiq +17 -0
  5. data/lib/active_job/queue_adapters/sidekiq_adapter.rb +8 -8
  6. data/lib/sidekiq/api.rb +110 -35
  7. data/lib/sidekiq/capsule.rb +0 -1
  8. data/lib/sidekiq/cli.rb +2 -3
  9. data/lib/sidekiq/client.rb +8 -1
  10. data/lib/sidekiq/component.rb +3 -0
  11. data/lib/sidekiq/config.rb +4 -8
  12. data/lib/sidekiq/job.rb +14 -1
  13. data/lib/sidekiq/job_retry.rb +1 -1
  14. data/lib/sidekiq/launcher.rb +1 -1
  15. data/lib/sidekiq/manager.rb +2 -1
  16. data/lib/sidekiq/paginator.rb +8 -2
  17. data/lib/sidekiq/profiler.rb +1 -1
  18. data/lib/sidekiq/redis_client_adapter.rb +6 -2
  19. data/lib/sidekiq/scheduled.rb +2 -5
  20. data/lib/sidekiq/testing.rb +1 -0
  21. data/lib/sidekiq/tui/controls.rb +53 -0
  22. data/lib/sidekiq/tui/filtering.rb +53 -0
  23. data/lib/sidekiq/tui/tabs/base_tab.rb +204 -0
  24. data/lib/sidekiq/tui/tabs/busy.rb +118 -0
  25. data/lib/sidekiq/tui/tabs/dead.rb +19 -0
  26. data/lib/sidekiq/tui/tabs/home.rb +144 -0
  27. data/lib/sidekiq/tui/tabs/metrics.rb +131 -0
  28. data/lib/sidekiq/tui/tabs/queues.rb +95 -0
  29. data/lib/sidekiq/tui/tabs/retries.rb +19 -0
  30. data/lib/sidekiq/tui/tabs/scheduled.rb +19 -0
  31. data/lib/sidekiq/tui/tabs/set_tab.rb +96 -0
  32. data/lib/sidekiq/tui/tabs.rb +15 -0
  33. data/lib/sidekiq/tui.rb +276 -913
  34. data/lib/sidekiq/version.rb +1 -1
  35. data/lib/sidekiq/web/action.rb +2 -2
  36. data/lib/sidekiq/web/application.rb +14 -1
  37. data/lib/sidekiq/web/helpers.rb +34 -9
  38. data/lib/sidekiq/web/router.rb +2 -2
  39. data/lib/sidekiq.rb +1 -1
  40. data/sidekiq.gemspec +2 -2
  41. data/web/assets/stylesheets/style.css +2 -0
  42. data/web/locales/ar.yml +1 -1
  43. data/web/locales/fa.yml +1 -1
  44. data/web/locales/gd.yml +12 -2
  45. data/web/locales/he.yml +1 -1
  46. data/web/locales/pt-BR.yml +1 -1
  47. data/web/locales/ur.yml +1 -1
  48. data/web/locales/zh-TW.yml +1 -1
  49. data/web/views/_job_info.html.erb +8 -0
  50. data/web/views/_paging.html.erb +1 -1
  51. data/web/views/busy.html.erb +49 -40
  52. data/web/views/retries.html.erb +3 -0
  53. metadata +17 -4
  54. data/bin/tui +0 -5
@@ -0,0 +1,95 @@
1
+ require_relative "base_tab"
2
+
3
+ module Sidekiq
4
+ class TUI
5
+ module Tabs
6
+ class Queues < BaseTab
7
+ def features
8
+ %i[selectable]
9
+ end
10
+
11
+ def controls
12
+ @controls ||= super + [
13
+ {code: "D", modifiers: ["shift"], display: "D", description: "Delete",
14
+ action: ->(tui, tab) { tab.delete_queue! }, refresh: true},
15
+ {code: "p", description: "Pause/Unpause Queue",
16
+ action: ->(tui, tab) { tab.toggle_pause_queue! }}
17
+ ]
18
+ end
19
+
20
+ def delete_queue!
21
+ each_selection do |qname|
22
+ Sidekiq::Queue.new(qname).clear
23
+ end
24
+ end
25
+
26
+ def toggle_pause_queue!
27
+ return unless Sidekiq.pro?
28
+
29
+ each_selection do |qname|
30
+ queue = Sidekiq::Queue.new(qname)
31
+ if queue.paused?
32
+ queue.unpause!
33
+ else
34
+ queue.pause!
35
+ end
36
+ end
37
+ end
38
+
39
+ def refresh_data
40
+ refresh_data_for_stats
41
+
42
+ queue_summaries = Sidekiq::Stats.new.queue_summaries.sort_by(&:name)
43
+
44
+ selected = Array(@data[:selected])
45
+ queues = queue_summaries.map { |queue_summary|
46
+ row_cells = [
47
+ selected.index(queue_summary.name) ? "✅" : "",
48
+ queue_summary.name,
49
+ queue_summary.size.to_s,
50
+ number_with_delimiter(queue_summary.latency, {precision: 2})
51
+ ]
52
+ row_cells << (queue_summary.paused? ? "✅" : "") if Sidekiq.pro?
53
+ row_cells
54
+ }
55
+
56
+ table_row_ids = queue_summaries.map(&:name)
57
+
58
+ @data[:queues] = queues
59
+ @data[:table] = {row_ids: table_row_ids}
60
+ end
61
+
62
+ def render(tui, frame, area)
63
+ header = ["☑️", "Queue", "Size", "Latency"].map { |x| t(x) }
64
+ header << "Paused?" if Sidekiq.pro?
65
+
66
+ chunks = tui.layout_split(
67
+ area,
68
+ direction: :vertical,
69
+ constraints: [
70
+ tui.constraint_length(4), # Stats
71
+ tui.constraint_fill(1) # Table
72
+ ]
73
+ )
74
+
75
+ render_stats_section(tui, frame, chunks[0])
76
+ render_table(tui, frame, chunks[1]) do
77
+ {
78
+ title: t(name),
79
+ header:,
80
+ widths: header.map.with_index { |_, idx|
81
+ tui.constraint_length((idx == 1) ? 60 : 10)
82
+ },
83
+ rows: @data[:queues].map.with_index { |cells, idx|
84
+ tui.table_row(
85
+ cells:,
86
+ style: idx.even? ? nil : tui.style(bg: :dark_gray)
87
+ )
88
+ }
89
+ }
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,19 @@
1
+ require_relative "base_tab"
2
+ require_relative "set_tab"
3
+
4
+ module Sidekiq
5
+ class TUI
6
+ module Tabs
7
+ class Retries < BaseTab
8
+ include SetTab
9
+
10
+ def set_class = Sidekiq::RetrySet
11
+
12
+ def refresh_data
13
+ refresh_data_for_stats
14
+ refresh_data_for_set
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require_relative "base_tab"
2
+ require_relative "set_tab"
3
+
4
+ module Sidekiq
5
+ class TUI
6
+ module Tabs
7
+ class Scheduled < BaseTab
8
+ include SetTab
9
+
10
+ def set_class = Sidekiq::ScheduledSet
11
+
12
+ def refresh_data
13
+ refresh_data_for_stats
14
+ refresh_data_for_set
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,96 @@
1
+ module Sidekiq
2
+ class TUI
3
+ module Tabs
4
+ module SetTab
5
+ include Sidekiq::Paginator
6
+ include Filtering
7
+
8
+ def features
9
+ %i[selectable pageable filterable]
10
+ end
11
+
12
+ def controls
13
+ @controls ||= super + [{code: "D", modifiers: ["shift"], display: "D", description: "Delete",
14
+ action: ->(tui, tab) { tab.alter_rows!(:delete) }, refresh: true},
15
+ {code: "R", modifiers: ["shift"], display: "R", description: "Retry",
16
+ action: ->(tui, tab) { tab.alter_rows!(:retry) }, refresh: true},
17
+ {code: "E", modifiers: ["shift"], display: "E", description: "Enqueue",
18
+ action: ->(tui, tab) { tab.alter_rows!(:add_to_queue) }, refresh: true},
19
+ {code: "K", modifiers: ["shift"], display: "K", description: "Kill",
20
+ action: ->(tui, tab) { tab.alter_rows!(:kill) }, refresh: true}]
21
+ end
22
+
23
+ def alter_rows!(action)
24
+ # log(to_s, @data[:selected])
25
+ set = set_class.new
26
+ each_selection do |id|
27
+ score, jid = id.split("|")
28
+ item = set.fetch(score, jid)&.first
29
+ item&.send(action)
30
+ end
31
+ end
32
+
33
+ def refresh_data_for_set
34
+ set = set_class.new
35
+ f = current_filter
36
+ pager, rows, current, total = if f && f.size > 2
37
+ rows = set.scan(f).to_a
38
+ sz = rows.size
39
+ [Sidekiq::TUI::PageOptions.new(1, sz), rows, 1, sz]
40
+ else
41
+ pager = @data.dig(:table, :pager) || Sidekiq::TUI::PageOptions.new(1, 25)
42
+ current, total, items = page(set.name, pager.page, pager.size)
43
+ rows = items.map { |msg, score| Sidekiq::SortedEntry.new(nil, score, msg) }
44
+ [pager, rows, current, total]
45
+ end
46
+
47
+ @data.merge!(
48
+ table: {pager:, rows:, current_page: current, total:,
49
+ next_page: (current * pager.size < total) ? pager.page + 1 : nil,
50
+ row_ids: rows.map { |job| [job.score, job["jid"]].join("|") }}
51
+ )
52
+ end
53
+
54
+ def render(tui, frame, area)
55
+ chunks = tui.layout_split(
56
+ area,
57
+ direction: :vertical,
58
+ constraints: [
59
+ tui.constraint_length(4), # Stats
60
+ tui.constraint_fill(1) # Table
61
+ ]
62
+ )
63
+
64
+ render_stats_section(tui, frame, chunks[0])
65
+ render_table(tui, frame, chunks[1]) do
66
+ {
67
+ title: t(name),
68
+ header: ["☑️", "When", "Queue", "Job", "Arguments"].map { |x| t(x) },
69
+ widths: [
70
+ tui.constraint_length(5),
71
+ tui.constraint_length(24),
72
+ tui.constraint_length(20),
73
+ tui.constraint_length(30),
74
+ tui.constraint_fill(1)
75
+ ]
76
+ }.tap do |h|
77
+ rows = @data[:table][:rows].map.with_index { |entry, idx|
78
+ tui.table_row(
79
+ cells: [
80
+ selected?(entry) ? "✅" : "",
81
+ entry.at,
82
+ entry.queue,
83
+ entry.display_class,
84
+ entry.display_args
85
+ ],
86
+ style: idx.even? ? nil : tui.style(bg: :dark_gray)
87
+ )
88
+ }
89
+ h[:rows] = rows
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,15 @@
1
+ require_relative "tabs/home"
2
+ require_relative "tabs/busy"
3
+ require_relative "tabs/queues"
4
+ require_relative "tabs/scheduled"
5
+ require_relative "tabs/retries"
6
+ require_relative "tabs/dead"
7
+ require_relative "tabs/metrics"
8
+
9
+ module Sidekiq
10
+ class TUI
11
+ module Tabs
12
+ All = Set.new([Home, Busy, Queues, Scheduled, Retries, Dead, Metrics])
13
+ end
14
+ end
15
+ end