Class: Admin::ProgressJobsController

Inherits:
BaseController
  • Object
show all
Defined in:
lib/generators/open_loam/install/templates/admin/progress_jobs_controller.rb

Overview

Long-running task progress (OpenLoam::ProgressJob) — a tenant-scoped list of recent jobs with a live bar (the open_loam.progress.updated SSE event updates it). Your app starts jobs with OpenLoam::Progress.start in its own background jobs; a running one can be cancelled cooperatively here.

Constant Summary

Constants included from Pagination

Admin::Pagination::PER_PAGE

Instance Method Summary collapse

Methods inherited from BaseController

skip_authorization!

Methods included from Pagination

#paginate

Instance Method Details

#cancel ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/generators/open_loam/install/templates/admin/progress_jobs_controller.rb', line 14

def cancel
  job = OpenLoam::ProgressJob.find(params[:id])
  # Manager-or-owner: a member must not cancel another user's job.
  authorized!
  raise OpenLoam::NotAuthorizedError unless current_role == :manager || job.actor_id == current_actor&.id
  job.cancel! if job.running?
  redirect_to admin_progress_jobs_path, notice: "Job cancelled."
end

#index ⇒ Object



10
11
12
# File 'lib/generators/open_loam/install/templates/admin/progress_jobs_controller.rb', line 10

def index
  @jobs = OpenLoam::ProgressJob.recent.limit(20)
end