Module: SidekiqScheduler::Web

Defined in:
lib/sidekiq-scheduler/web.rb

Overview

Hook into Sidekiq::Web Sinatra app which adds a new '/recurring-jobs' page

Constant Summary collapse

VIEW_PATH =
File.expand_path('../../../web/views', __FILE__)

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sidekiq-scheduler/web.rb', line 11

def self.registered(app)
  app.get '/recurring-jobs' do
    @presented_jobs = JobPresenter.build_collection(Sidekiq.schedule!)

    erb File.read(File.join(VIEW_PATH, 'recurring_jobs.erb'))
  end

  app.get '/recurring-jobs/:name/enqueue' do
    schedule = Sidekiq.get_schedule(params[:name])
    SidekiqScheduler::Scheduler.instance.enqueue_job(schedule)
    redirect "#{root_path}recurring-jobs"
  end

  app.get '/recurring-jobs/:name/toggle' do
    Sidekiq.reload_schedule!

    SidekiqScheduler::Scheduler.instance.toggle_job_enabled(params[:name])
    redirect "#{root_path}recurring-jobs"
  end
end