Module: RoundhouseUi::JobSetBrowsing
- Extended by:
- ActiveSupport::Concern
- Included in:
- DeadController, RetriesController, ScheduledController
- Defined in:
- app/controllers/concerns/roundhouse_ui/job_set_browsing.rb
Overview
Shared search + pagination over a Sidekiq job set (dead, retry, scheduled). Keeps the controllers from duplicating the scan/filter/window logic.
Constant Summary collapse
- PER_PAGE =
25- BULK_CAP =
safety ceiling on a single match-set action
1_000
Instance Method Summary collapse
-
#browse(set, query, page, per = PER_PAGE) ⇒ Object
Returns [entries_for_page, has_next?].
-
#bulk_apply(set, query, op, cap = BULK_CAP) ⇒ Object
Apply an op ("retry"/"delete") to every entry matching the query, capped at BULK_CAP.
- #entry_matches?(entry, query) ⇒ Boolean
Instance Method Details
#browse(set, query, page, per = PER_PAGE) ⇒ Object
Returns [entries_for_page, has_next?]. Scans only far enough to fill the requested page plus one (to know if a next page exists) — never loads the whole set, so a 50k dead set stays cheap to page through.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/controllers/concerns/roundhouse_ui/job_set_browsing.rb', line 13 def browse(set, query, page, per = PER_PAGE) start = (page - 1) * per jobs = [] has_next = false matched = 0 set.each do |entry| next if query.present? && !entry_matches?(entry, query) if matched < start matched += 1 elsif jobs.size < per jobs << entry matched += 1 else has_next = true break end end [ jobs, has_next ] end |
#bulk_apply(set, query, op, cap = BULK_CAP) ⇒ Object
Apply an op ("retry"/"delete") to every entry matching the query, capped at BULK_CAP. Entries are collected first, then acted on — mutating a Sidekiq set mid-iteration skips entries. Returns [count_acted_on, capped?].
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/controllers/concerns/roundhouse_ui/job_set_browsing.rb', line 39 def bulk_apply(set, query, op, cap = BULK_CAP) matches = [] capped = false set.each do |entry| next if query.present? && !entry_matches?(entry, query) matches << entry if matches.size >= cap capped = true break end end matches.each { |entry| op == "delete" ? entry.delete : entry.retry } [ matches.size, capped ] end |
#entry_matches?(entry, query) ⇒ Boolean
55 56 57 58 59 |
# File 'app/controllers/concerns/roundhouse_ui/job_set_browsing.rb', line 55 def entry_matches?(entry, query) needle = query.downcase [ entry.klass, entry.jid, entry.item["error_class"], entry.item["error_message"], entry.args.to_s ] .any? { |hay| hay.to_s.downcase.include?(needle) } end |