Class: RoundhouseUi::QueuesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- RoundhouseUi::QueuesController
- Includes:
- JobSetBrowsing
- Defined in:
- app/controllers/roundhouse_ui/queues_controller.rb
Constant Summary collapse
- INDEX_FILTER_KEYS =
A queue is not a job, so class= and error= have nothing to apply to here. queue= narrows the LIST to one queue by exact name; free text stays a substring on the name. One grammar, one bar, honest about what it honours on this page.
%w[queue text].freeze
Constants included from JobSetBrowsing
JobSetBrowsing::BULK_CAP, JobSetBrowsing::FILTER_KEYS, JobSetBrowsing::MAX_QUERY_LENGTH, JobSetBrowsing::NO_FILTER, JobSetBrowsing::PER_PAGE
Constants inherited from ApplicationController
ApplicationController::AUDIT_VERBS
Instance Method Summary collapse
- #index ⇒ Object
- #pause ⇒ Object
-
#purge ⇒ Object
Real, OSS-supported destructive action: empties the queue in Redis.
- #resume ⇒ Object
-
#show ⇒ Object
The jobs waiting on one queue — what Sidekiq Web shows and we did not.
-
#snapshot ⇒ Object
Non-destructive backup — allowed even in read-only mode.
Methods included from JobSetBrowsing
#active_filters, #browse, #bulk_apply, #bulk_filter_present?, #bulk_matches, #bulk_refusal_reason, #class_filter, #entry_matches?, #entry_selected?, #entry_tagged?, #entry_tags, #error_filter, #filter, #load_filters, #query_refused?, #queue_filter, #tag_cache_for, #tag_filter
Methods inherited from ApplicationController
allow_in_read_only, guard_in_read_only, #redirect_to, requires_capability
Instance Method Details
#index ⇒ Object
16 17 18 19 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 |
# File 'app/controllers/roundhouse_ui/queues_controller.rb', line 16 def index # Re-parsed against this page's key subset, not the job-set one: @filter from # the concern's before_action honours class/error/tag, none of which can narrow # a list of queues, and a pill that filters nothing is the phantom filter the # bar exists to prevent. @filter = FilterQuery.from_params(params, keys: INDEX_FILTER_KEYS) @query = @filter.text # queue_summaries reads depth and latency for every queue in one batch. # Mapping over backend.queues instead costs a round-trip per queue per # column, which on an app with sixty queues is most of a page render. @queues = backend.queue_summaries @total_size = @queues.sum(&:size) @queues = [] if @filter.invalid? @queues = @queues.select { |q| q.name.to_s.downcase.include?(@query.downcase) } if @query.present? # queue= is exact, the same as everywhere else, so a queue pill clicked on a # job row and one typed here mean the same thing. @queues = @queues.select { |q| @filter.matches_facet?(:queue, q.name) } if @filter.queue # Worst first, matching the dashboard and Sidekiq's own convention. Sorted # by name the one backed-up queue sits wherever the alphabet puts it, # behind however many rows of zeros. @queues = @queues.sort_by { |q| [ -q.latency.to_f, -q.size.to_i, q.name.to_s ] } @paused = backend.paused_queues # State filter. Counts come from the unfiltered set so the chips still say # how many are on the other side of the filter — a chip that reads "0" once # you have selected it is useless for getting back. @state = params[:state].to_s @state_counts = { "paused" => @queues.count { |q| @paused.include?(q.name) } } @state_counts["active"] = @queues.size - @state_counts["paused"] case @state when "paused" then @queues = @queues.select { |q| @paused.include?(q.name) } when "active" then @queues = @queues.reject { |q| @paused.include?(q.name) } end # Native-pause backends (Solid Queue) enforce pauses without a fetcher, so # they never trigger the "not enforced" warning. @fetch_installed = backend.supports?(:native_pause) || (backend.respond_to?(:fetch_installed?) && backend.fetch_installed?) end |
#pause ⇒ Object
74 75 76 77 |
# File 'app/controllers/roundhouse_ui/queues_controller.rb', line 74 def pause backend.pause(params[:name]) redirect_to queues_path, notice: "Paused “#{params[:name]}”." end |
#purge ⇒ Object
Real, OSS-supported destructive action: empties the queue in Redis.
69 70 71 72 |
# File 'app/controllers/roundhouse_ui/queues_controller.rb', line 69 def purge backend.queue(params[:name]).clear redirect_to queues_path, notice: "Purged queue “#{params[:name]}”." end |
#resume ⇒ Object
79 80 81 82 |
# File 'app/controllers/roundhouse_ui/queues_controller.rb', line 79 def resume backend.resume(params[:name]) redirect_to queues_path, notice: "Resumed “#{params[:name]}”." end |
#show ⇒ Object
The jobs waiting on one queue — what Sidekiq Web shows and we did not. Goes through the shared browse path, so it pages rather than loading a queue that could hold hundreds of thousands of jobs, and inherits search and the tag filter for free.
58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/roundhouse_ui/queues_controller.rb', line 58 def show @name = params[:name] @page = [ params[:page].to_i, 1 ].max summary = backend.queue_summaries.find { |q| q.name == @name } @total = summary&.size.to_i @latency = summary&.latency @paused = backend.paused_queues.include?(@name) @jobs, @has_next = browse(backend.queue_jobs(@name), @query, @page, PER_PAGE, tag: @tag) end |
#snapshot ⇒ Object
Non-destructive backup — allowed even in read-only mode.
85 86 87 88 |
# File 'app/controllers/roundhouse_ui/queues_controller.rb', line 85 def snapshot snap = RoundhouseUi::Snapshots.take(params[:name]) redirect_to queues_path, notice: "Snapshot saved — #{snap[:count]} job(s) from “#{params[:name]}”." end |