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
Instance Method Summary collapse
-
#browse(set, query, page, per = PER_PAGE) ⇒ Object
Returns [entries_for_page, has_next?].
- #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.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/concerns/roundhouse_ui/job_set_browsing.rb', line 12 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 |
#entry_matches?(entry, query) ⇒ Boolean
35 36 37 38 39 |
# File 'app/controllers/concerns/roundhouse_ui/job_set_browsing.rb', line 35 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 |