Class: RoundhouseUi::JobsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- RoundhouseUi::JobsController
- Defined in:
- app/controllers/roundhouse_ui/jobs_controller.rb
Overview
Enqueue new jobs and edit/re-enqueue existing ones. Opt-in via RoundhouseUi.allow_job_editing (off by default — a sharp tool).
Sidekiq has no in-place edit: a job in a set is keyed by its payload, so an "edit" is delete-the-old + push-the-modified.
Constant Summary collapse
- REDIRECTS =
{ "dead" => :dead_set_path, "retry" => :retries_path, "scheduled" => :scheduled_path }.freeze
Constants inherited from ApplicationController
ApplicationController::AUDIT_VERBS
Instance Method Summary collapse
- #create ⇒ Object
- #edit ⇒ Object
- #new ⇒ Object
-
#show ⇒ Object
Read-only inspection — available without allow_job_editing.
- #update ⇒ Object
Methods inherited from ApplicationController
allow_in_read_only, guard_in_read_only, #redirect_to, requires_capability
Instance Method Details
#create ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/roundhouse_ui/jobs_controller.rb', line 26 def create args = parse_args!(params[:args]) klass = params[:job_class].to_s.strip raise ArgumentError, "Job class is required" if klass.empty? queue = params[:queue].presence || "default" backend.push("class" => klass, "queue" => queue, "args" => args) redirect_to queues_path, notice: "Enqueued #{klass} → #{queue}." rescue ArgumentError => e render_form_error(:new, jobs_path, e) end |
#edit ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/roundhouse_ui/jobs_controller.rb', line 38 def edit @entry = find_entry or return redirect_to(root_path, alert: "Job not found.") @mode = :edit @job = { "class" => @entry.item["class"], "queue" => @entry.queue, "args" => JSON.pretty_generate(@entry.item["args"] || []) } @action_path = job_path(set: params[:set], jid: params[:jid]) end |
#new ⇒ Object
20 21 22 23 24 |
# File 'app/controllers/roundhouse_ui/jobs_controller.rb', line 20 def new @mode = :new @job = { "class" => "", "queue" => "default", "args" => "[]" } @action_path = jobs_path end |
#show ⇒ Object
Read-only inspection — available without allow_job_editing.
15 16 17 18 |
# File 'app/controllers/roundhouse_ui/jobs_controller.rb', line 15 def show @set = params[:set] @entry = find_entry or return redirect_to(root_path, alert: "Job not found.") end |
#update ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/controllers/roundhouse_ui/jobs_controller.rb', line 49 def update entry = find_entry or return redirect_to(root_path, alert: "Job not found.") args = parse_args!(params[:args]) klass = params[:job_class].presence || entry.item["class"] queue = params[:queue].presence || entry.queue # Push BEFORE delete. Reversed, a backend that cannot push (Solid Queue raises # NotImplementedError) left the job deleted and gone. backend.push("class" => klass, "queue" => queue, "args" => args) entry.delete redirect_to send(REDIRECTS[params[:set]]), notice: "Edited & re-enqueued #{klass} → #{queue}." rescue ArgumentError => e @action_path = job_path(set: params[:set], jid: params[:jid]) render_form_error(:edit, @action_path, e) end |