Class: Admin::ScheduledJobsController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- BaseController
- Admin::ScheduledJobsController
- Defined in:
- lib/generators/open_loam/install/templates/admin/scheduled_jobs_controller.rb
Overview
Recurring schedules (OpenLoam::ScheduledJob) — manager-only. List/create/edit/
delete a tenant's schedules, toggle active, and "run now". The runner
(open_loam:scheduler:tick, wired to system cron) is what fires them on schedule.
Constant Summary
Constants included from Pagination
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #run_now ⇒ Object
- #update ⇒ Object
Methods inherited from BaseController
Methods included from Pagination
Instance Method Details
#create ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/generators/open_loam/install/templates/admin/scheduled_jobs_controller.rb', line 17 def create # scope is forced to "tenant": a tenant admin must never create a # "system" schedule (which would run with no tenant context). System # schedules are created only by the app/console. @job = OpenLoam::ScheduledJob.new(job_params.merge(scope: "tenant")) @job.next_run_at ||= safe_next_run(@job) if @job.save redirect_to admin_scheduled_jobs_path, notice: "Schedule created." else render :new, status: :unprocessable_entity end end |
#destroy ⇒ Object
42 43 44 45 |
# File 'lib/generators/open_loam/install/templates/admin/scheduled_jobs_controller.rb', line 42 def destroy @job.destroy! redirect_to admin_scheduled_jobs_path, notice: "Schedule deleted." end |
#edit ⇒ Object
30 |
# File 'lib/generators/open_loam/install/templates/admin/scheduled_jobs_controller.rb', line 30 def edit; end |
#index ⇒ Object
9 10 11 |
# File 'lib/generators/open_loam/install/templates/admin/scheduled_jobs_controller.rb', line 9 def index @jobs = OpenLoam::ScheduledJob.order(:key) end |
#new ⇒ Object
13 14 15 |
# File 'lib/generators/open_loam/install/templates/admin/scheduled_jobs_controller.rb', line 13 def new @job = OpenLoam::ScheduledJob.new(scope: "tenant", active: true, schedule: "0 3 * * *") end |
#run_now ⇒ Object
47 48 49 50 |
# File 'lib/generators/open_loam/install/templates/admin/scheduled_jobs_controller.rb', line 47 def run_now OpenLoam::Scheduler.run_now(@job) redirect_to admin_scheduled_jobs_path, notice: "#{@job.name} enqueued." end |
#update ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/generators/open_loam/install/templates/admin/scheduled_jobs_controller.rb', line 32 def update @job.assign_attributes(job_params) @job.next_run_at = safe_next_run(@job) if @job.schedule_changed? || @job.timezone_changed? if @job.save redirect_to admin_scheduled_jobs_path, notice: "Schedule updated." else render :edit, status: :unprocessable_entity end end |