Module: Sidecloq::Web

Defined in:
lib/sidecloq/web.rb

Overview

Plugin for sidekiq-web

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/sidecloq/web.rb', line 6

def self.registered(app)
  app.get '/recurring' do
    @schedule = Schedule.from_redis

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

  app.post '/recurring/:name/enqueue' do |name|
    job_name = respond_to?(:route_params) ? route_params[:name] : name

    # rubocop:disable Lint/AssignmentInCondition
    if spec = Sidecloq::Schedule.from_redis.job_specs[job_name]
      JobEnqueuer.new(spec).enqueue
    end
    # rubocop:enableLint/AssignmentInCondition
    redirect "#{root_path}recurring"
  end
end