2013-08-22 03:32:42 -04:00
|
|
|
require 'erb'
|
2013-04-29 17:56:05 -04:00
|
|
|
require 'yaml'
|
2012-03-04 15:58:16 -05:00
|
|
|
require 'sinatra/base'
|
2013-05-16 11:27:10 -04:00
|
|
|
|
2013-04-29 17:56:05 -04:00
|
|
|
require 'sidekiq'
|
|
|
|
require 'sidekiq/api'
|
2012-07-18 01:14:15 -04:00
|
|
|
require 'sidekiq/paginator'
|
2013-10-13 18:56:17 -04:00
|
|
|
require 'sidekiq/web_helpers'
|
2012-07-18 01:14:15 -04:00
|
|
|
|
2012-03-04 15:58:16 -05:00
|
|
|
module Sidekiq
|
|
|
|
class Web < Sinatra::Base
|
2012-07-18 01:14:15 -04:00
|
|
|
include Sidekiq::Paginator
|
|
|
|
|
2013-07-28 18:02:43 -04:00
|
|
|
set :root, File.expand_path(File.dirname(__FILE__) + "/../../web")
|
|
|
|
set :public_folder, Proc.new { "#{root}/assets" }
|
|
|
|
set :views, Proc.new { "#{root}/views" }
|
2013-10-21 15:07:18 -04:00
|
|
|
set :locales, ["#{root}/locales"]
|
2012-09-30 08:57:51 -04:00
|
|
|
|
2013-10-13 18:56:17 -04:00
|
|
|
helpers WebHelpers
|
2012-03-06 23:17:42 -05:00
|
|
|
|
2013-10-13 18:56:17 -04:00
|
|
|
DEFAULT_TABS = {
|
|
|
|
"Dashboard" => '',
|
|
|
|
"Workers" => 'workers',
|
|
|
|
"Queues" => 'queues',
|
|
|
|
"Retries" => 'retries',
|
|
|
|
"Scheduled" => 'scheduled',
|
2014-02-09 17:56:01 -05:00
|
|
|
"Dead" => 'morgue',
|
2013-10-13 18:56:17 -04:00
|
|
|
}
|
2013-05-30 00:07:49 -04:00
|
|
|
|
2013-10-13 18:56:17 -04:00
|
|
|
class << self
|
|
|
|
def default_tabs
|
|
|
|
DEFAULT_TABS
|
2013-04-15 13:43:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def custom_tabs
|
2013-10-13 18:56:17 -04:00
|
|
|
@custom_tabs ||= {}
|
2013-08-22 03:32:42 -04:00
|
|
|
end
|
2013-10-13 18:56:17 -04:00
|
|
|
alias_method :tabs, :custom_tabs
|
2012-03-05 23:53:14 -05:00
|
|
|
end
|
|
|
|
|
2013-02-20 11:56:53 -05:00
|
|
|
get "/workers" do
|
2014-02-21 20:59:32 -05:00
|
|
|
erb :workers
|
2012-03-04 15:58:16 -05:00
|
|
|
end
|
2012-03-05 23:53:14 -05:00
|
|
|
|
2012-06-08 20:20:11 -04:00
|
|
|
get "/queues" do
|
2013-06-01 17:54:29 -04:00
|
|
|
@queues = Sidekiq::Queue.all
|
2013-08-21 18:38:52 -04:00
|
|
|
erb :queues
|
2012-06-08 20:20:11 -04:00
|
|
|
end
|
|
|
|
|
2012-03-05 23:53:14 -05:00
|
|
|
get "/queues/:name" do
|
2012-03-17 12:41:24 -04:00
|
|
|
halt 404 unless params[:name]
|
2012-07-18 01:14:15 -04:00
|
|
|
@count = (params[:count] || 25).to_i
|
2012-03-05 23:53:14 -05:00
|
|
|
@name = params[:name]
|
2012-07-18 01:14:15 -04:00
|
|
|
(@current_page, @total_size, @messages) = page("queue:#{@name}", params[:page], @count)
|
|
|
|
@messages = @messages.map {|msg| Sidekiq.load_json(msg) }
|
2013-08-21 18:38:52 -04:00
|
|
|
erb :queue
|
2012-03-05 23:53:14 -05:00
|
|
|
end
|
2012-03-29 13:48:06 -04:00
|
|
|
|
2012-06-05 10:51:18 -04:00
|
|
|
post "/reset" do
|
|
|
|
reset_worker_list
|
|
|
|
redirect root_path
|
|
|
|
end
|
|
|
|
|
2012-05-02 23:19:59 -04:00
|
|
|
post "/queues/:name" do
|
2012-11-25 21:43:48 -05:00
|
|
|
Sidekiq::Queue.new(params[:name]).clear
|
2012-06-08 20:20:11 -04:00
|
|
|
redirect "#{root_path}queues"
|
2012-05-02 23:19:59 -04:00
|
|
|
end
|
|
|
|
|
2012-10-23 19:11:14 -04:00
|
|
|
post "/queues/:name/delete" do
|
2012-12-02 16:23:05 -05:00
|
|
|
Sidekiq::Job.new(params[:key_val], params[:name]).delete
|
2013-10-13 18:56:17 -04:00
|
|
|
redirect_with_query("#{root_path}queues/#{params[:name]}")
|
2012-10-23 19:11:14 -04:00
|
|
|
end
|
|
|
|
|
2014-02-09 17:56:01 -05:00
|
|
|
get '/morgue' do
|
|
|
|
@count = (params[:count] || 25).to_i
|
|
|
|
(@current_page, @total_size, @dead) = page("dead", params[:page], @count)
|
|
|
|
@dead = @dead.map {|msg, score| Sidekiq::SortedEntry.new(nil, score, msg) }
|
|
|
|
erb :morgue
|
|
|
|
end
|
|
|
|
|
|
|
|
get "/morgue/:key" do
|
|
|
|
halt 404 unless params['key']
|
|
|
|
@dead = Sidekiq::DeadSet.new.fetch(*parse_params(params['key'])).first
|
|
|
|
redirect "#{root_path}morgue" if @dead.nil?
|
|
|
|
erb :dead
|
|
|
|
end
|
|
|
|
|
|
|
|
post '/morgue' do
|
|
|
|
halt 404 unless params['key']
|
|
|
|
|
|
|
|
params['key'].each do |key|
|
|
|
|
job = Sidekiq::DeadSet.new.fetch(*parse_params(key)).first
|
|
|
|
next unless job
|
|
|
|
if params['retry']
|
|
|
|
job.retry
|
|
|
|
elsif params['delete']
|
|
|
|
job.delete
|
|
|
|
end
|
|
|
|
end
|
|
|
|
redirect_with_query("#{root_path}morgue")
|
|
|
|
end
|
|
|
|
|
|
|
|
post "/morgue/all/delete" do
|
|
|
|
Sidekiq::DeadSet.new.clear
|
|
|
|
redirect "#{root_path}morgue"
|
|
|
|
end
|
|
|
|
|
|
|
|
post "/morgue/all/retry" do
|
|
|
|
Sidekiq::DeadSet.new.retry_all
|
|
|
|
redirect "#{root_path}morgue"
|
|
|
|
end
|
|
|
|
|
|
|
|
post "/morgue/:key" do
|
|
|
|
halt 404 unless params['key']
|
|
|
|
job = Sidekiq::DeadSet.new.fetch(*parse_params(params['key'])).first
|
|
|
|
if job
|
|
|
|
if params['retry']
|
|
|
|
job.retry
|
|
|
|
elsif params['delete']
|
|
|
|
job.delete
|
|
|
|
end
|
|
|
|
end
|
|
|
|
redirect_with_query("#{root_path}morgue")
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-05-11 19:48:03 -04:00
|
|
|
get '/retries' do
|
2012-07-18 01:14:15 -04:00
|
|
|
@count = (params[:count] || 25).to_i
|
|
|
|
(@current_page, @total_size, @retries) = page("retry", params[:page], @count)
|
2013-11-10 13:40:21 -05:00
|
|
|
@retries = @retries.map {|msg, score| Sidekiq::SortedEntry.new(nil, score, msg) }
|
2013-08-21 18:38:52 -04:00
|
|
|
erb :retries
|
2012-05-11 19:48:03 -04:00
|
|
|
end
|
|
|
|
|
2012-11-26 14:53:22 -05:00
|
|
|
get "/retries/:key" do
|
|
|
|
halt 404 unless params['key']
|
|
|
|
@retry = Sidekiq::RetrySet.new.fetch(*parse_params(params['key'])).first
|
2012-11-26 11:22:48 -05:00
|
|
|
redirect "#{root_path}retries" if @retry.nil?
|
2013-08-21 18:38:52 -04:00
|
|
|
erb :retry
|
2012-05-25 23:21:42 -04:00
|
|
|
end
|
|
|
|
|
2012-05-11 19:48:03 -04:00
|
|
|
post '/retries' do
|
2012-11-26 14:53:22 -05:00
|
|
|
halt 404 unless params['key']
|
|
|
|
|
|
|
|
params['key'].each do |key|
|
|
|
|
job = Sidekiq::RetrySet.new.fetch(*parse_params(key)).first
|
2013-08-01 12:48:38 -04:00
|
|
|
next unless job
|
2012-11-26 14:53:22 -05:00
|
|
|
if params['retry']
|
|
|
|
job.retry
|
|
|
|
elsif params['delete']
|
|
|
|
job.delete
|
|
|
|
end
|
2012-05-11 19:48:03 -04:00
|
|
|
end
|
2013-10-13 18:56:17 -04:00
|
|
|
redirect_with_query("#{root_path}retries")
|
2012-05-11 19:48:03 -04:00
|
|
|
end
|
|
|
|
|
2012-11-25 21:43:48 -05:00
|
|
|
post "/retries/all/delete" do
|
|
|
|
Sidekiq::RetrySet.new.clear
|
|
|
|
redirect "#{root_path}retries"
|
|
|
|
end
|
|
|
|
|
|
|
|
post "/retries/all/retry" do
|
2013-02-19 23:36:59 -05:00
|
|
|
Sidekiq::RetrySet.new.retry_all
|
2012-11-25 21:43:48 -05:00
|
|
|
redirect "#{root_path}retries"
|
2012-05-11 19:48:03 -04:00
|
|
|
end
|
|
|
|
|
2012-11-26 14:53:22 -05:00
|
|
|
post "/retries/:key" do
|
|
|
|
halt 404 unless params['key']
|
|
|
|
job = Sidekiq::RetrySet.new.fetch(*parse_params(params['key'])).first
|
2013-08-15 22:52:50 -04:00
|
|
|
if job
|
|
|
|
if params['retry']
|
|
|
|
job.retry
|
|
|
|
elsif params['delete']
|
|
|
|
job.delete
|
|
|
|
end
|
2012-05-11 19:48:03 -04:00
|
|
|
end
|
2013-10-13 18:56:17 -04:00
|
|
|
redirect_with_query("#{root_path}retries")
|
2012-05-11 19:48:03 -04:00
|
|
|
end
|
|
|
|
|
2012-11-26 11:22:48 -05:00
|
|
|
get '/scheduled' do
|
|
|
|
@count = (params[:count] || 25).to_i
|
|
|
|
(@current_page, @total_size, @scheduled) = page("schedule", params[:page], @count)
|
2013-11-10 13:40:21 -05:00
|
|
|
@scheduled = @scheduled.map {|msg, score| Sidekiq::SortedEntry.new(nil, score, msg) }
|
2013-08-21 18:38:52 -04:00
|
|
|
erb :scheduled
|
2012-11-26 11:22:48 -05:00
|
|
|
end
|
|
|
|
|
2013-07-27 12:49:21 -04:00
|
|
|
get "/scheduled/:key" do
|
|
|
|
halt 404 unless params['key']
|
|
|
|
@job = Sidekiq::ScheduledSet.new.fetch(*parse_params(params['key'])).first
|
|
|
|
redirect "#{root_path}scheduled" if @job.nil?
|
2013-08-21 18:38:52 -04:00
|
|
|
erb :scheduled_job_info
|
2013-07-27 12:49:21 -04:00
|
|
|
end
|
|
|
|
|
2012-11-26 11:22:48 -05:00
|
|
|
post '/scheduled' do
|
2012-11-26 14:53:22 -05:00
|
|
|
halt 404 unless params['key']
|
2013-06-21 22:43:06 -04:00
|
|
|
|
2012-11-26 14:53:22 -05:00
|
|
|
params['key'].each do |key|
|
2013-06-21 22:43:06 -04:00
|
|
|
job = Sidekiq::ScheduledSet.new.fetch(*parse_params(key)).first
|
2013-08-15 22:52:50 -04:00
|
|
|
if job
|
|
|
|
if params['delete']
|
|
|
|
job.delete
|
|
|
|
elsif params['add_to_queue']
|
|
|
|
job.add_to_queue
|
|
|
|
end
|
2013-06-21 22:43:06 -04:00
|
|
|
end
|
2012-11-26 14:53:22 -05:00
|
|
|
end
|
2013-10-13 18:56:17 -04:00
|
|
|
redirect_with_query("#{root_path}scheduled")
|
2012-03-29 23:55:16 -04:00
|
|
|
end
|
2012-05-11 19:48:03 -04:00
|
|
|
|
2013-07-27 12:49:21 -04:00
|
|
|
post "/scheduled/:key" do
|
|
|
|
halt 404 unless params['key']
|
|
|
|
job = Sidekiq::ScheduledSet.new.fetch(*parse_params(params['key'])).first
|
2013-08-15 22:52:50 -04:00
|
|
|
if job
|
|
|
|
if params['add_to_queue']
|
|
|
|
job.add_to_queue
|
|
|
|
elsif params['delete']
|
|
|
|
job.delete
|
|
|
|
end
|
2013-07-27 12:49:21 -04:00
|
|
|
end
|
2013-10-13 18:56:17 -04:00
|
|
|
redirect_with_query("#{root_path}scheduled")
|
2013-07-27 12:49:21 -04:00
|
|
|
end
|
|
|
|
|
2013-02-20 11:56:53 -05:00
|
|
|
get '/' do
|
2013-10-13 18:56:17 -04:00
|
|
|
@redis_info = Sidekiq.redis { |conn| conn.info }.select{ |k, v| REDIS_KEYS.include? k }
|
2012-12-05 11:28:55 -05:00
|
|
|
stats_history = Sidekiq::Stats::History.new((params[:days] || 30).to_i)
|
|
|
|
@processed_history = stats_history.processed
|
|
|
|
@failed_history = stats_history.failed
|
2013-08-21 18:38:52 -04:00
|
|
|
erb :dashboard
|
2012-12-05 11:28:55 -05:00
|
|
|
end
|
|
|
|
|
2013-10-13 18:56:17 -04:00
|
|
|
REDIS_KEYS = %w(redis_stats uptime_in_days connected_clients used_memory_human used_memory_peak_human)
|
|
|
|
|
2012-12-12 11:49:20 -05:00
|
|
|
get '/dashboard/stats' do
|
2013-01-26 14:34:46 -05:00
|
|
|
sidekiq_stats = Sidekiq::Stats.new
|
2013-10-04 03:18:04 -04:00
|
|
|
queue = Sidekiq::Queue.new
|
2013-10-13 18:56:17 -04:00
|
|
|
redis_stats = Sidekiq.redis { |conn| conn.info }.select{ |k, v| REDIS_KEYS.include? k }
|
2013-01-26 14:34:46 -05:00
|
|
|
|
2012-12-05 11:28:55 -05:00
|
|
|
content_type :json
|
2012-12-28 20:55:00 -05:00
|
|
|
Sidekiq.dump_json({
|
2013-01-26 14:34:46 -05:00
|
|
|
sidekiq: {
|
|
|
|
processed: sidekiq_stats.processed,
|
|
|
|
failed: sidekiq_stats.failed,
|
2013-06-13 11:41:23 -04:00
|
|
|
busy: workers_size,
|
2013-01-26 14:34:46 -05:00
|
|
|
enqueued: sidekiq_stats.enqueued,
|
|
|
|
scheduled: sidekiq_stats.scheduled_size,
|
|
|
|
retries: sidekiq_stats.retry_size,
|
2013-10-04 12:44:45 -04:00
|
|
|
default_latency: queue.latency,
|
2013-01-26 14:34:46 -05:00
|
|
|
},
|
|
|
|
redis: redis_stats
|
2012-12-28 20:55:00 -05:00
|
|
|
})
|
2012-12-05 11:28:55 -05:00
|
|
|
end
|
|
|
|
|
2012-03-04 15:58:16 -05:00
|
|
|
end
|
|
|
|
end
|