module Sidekiq::Killswitch::Web

Constants

VIEW_PATH

Public Class Methods

registered(app) click to toggle source
# File lib/sidekiq/killswitch/web.rb, line 18
def self.registered(app)
  Sidekiq::WebApplication.helpers Helpers

  app.get '/kill-switches' do
    @worker_name_invalid = session.delete(:worker_name_invalid)
    @blackhole_workers = Killswitch.blackhole_workers
    @dead_queue_workers = Killswitch.dead_queue_workers

    erb File.read(File.join(VIEW_PATH, 'kill_switches.html.erb'))
  end

  # We should not worry about String escaping and NoSQL injection
  # https://redis.io/topics/security#string-escaping-and-nosql-injection
  app.post '/kill-switches/blackhole_add' do
    Killswitch.blackhole_add_worker(params['worker_name']) if validate_worker_name(params['worker_name'])

    redirect "#{root_path}kill-switches"
  end

  app.post '/kill-switches/blackhole_remove' do
    Killswitch.blackhole_remove_worker(params['worker_name']) if validate_worker_name(params['worker_name'])

    redirect "#{root_path}kill-switches"
  end

  app.post '/kill-switches/dead_queue_add' do
    Killswitch.dead_queue_add_worker(params['worker_name']) if validate_worker_name(params['worker_name'])

    redirect "#{root_path}kill-switches"
  end

  app.post '/kill-switches/dead_queue_remove' do
    Killswitch.dead_queue_remove_worker(params['worker_name']) if validate_worker_name(params['worker_name'])

    redirect "#{root_path}kill-switches"
  end
end