mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Implement compatibility interface with sinatra
This commit is contained in:
parent
91fd77d44e
commit
d05066dc1a
20 changed files with 185 additions and 129 deletions
|
@ -34,6 +34,10 @@ module Sidekiq
|
||||||
}
|
}
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
def settings
|
||||||
|
self
|
||||||
|
end
|
||||||
|
|
||||||
def default_tabs
|
def default_tabs
|
||||||
DEFAULT_TABS
|
DEFAULT_TABS
|
||||||
end
|
end
|
||||||
|
@ -47,12 +51,20 @@ module Sidekiq
|
||||||
@locales ||= LOCALES
|
@locales ||= LOCALES
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def views
|
||||||
|
@views ||= VIEWS
|
||||||
|
end
|
||||||
|
|
||||||
def session_secret=(secret)
|
def session_secret=(secret)
|
||||||
@secret = secret
|
@session_secret = secret
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_accessor :app_url, :session_secret
|
attr_accessor :app_url, :session_secret
|
||||||
attr_writer :locales
|
attr_writer :locales, :views
|
||||||
|
end
|
||||||
|
|
||||||
|
def settings
|
||||||
|
self.class.settings
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
|
|
|
@ -6,17 +6,35 @@ module Sidekiq
|
||||||
|
|
||||||
LOCATION = "Location".freeze
|
LOCATION = "Location".freeze
|
||||||
|
|
||||||
TEXT_HTML = { "Content-Type".freeze => "text/html".freeze }
|
CONTENT_TYPE = "Content-Type".freeze
|
||||||
APPLICATION_JSON = { "Content-Type".freeze => "application/json".freeze }
|
TEXT_HTML = { CONTENT_TYPE => "text/html".freeze }
|
||||||
|
APPLICATION_JSON = { CONTENT_TYPE => "application/json".freeze }
|
||||||
|
|
||||||
attr_accessor :env, :app
|
attr_accessor :env, :app, :type
|
||||||
|
|
||||||
|
def settings
|
||||||
|
Web.settings
|
||||||
|
end
|
||||||
|
|
||||||
def request
|
def request
|
||||||
@request ||= Rack::Request.new(env)
|
@request ||= Rack::Request.new(env)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def halt(res)
|
||||||
|
throw :halt, res
|
||||||
|
end
|
||||||
|
|
||||||
|
def redirect(location)
|
||||||
|
throw :halt, [302, { LOCATION => "#{request.base_url}#{location}" }, []]
|
||||||
|
end
|
||||||
|
|
||||||
def params
|
def params
|
||||||
request.params
|
indifferent_hash = Hash.new {|hash,key| hash[key.to_s] if Symbol === key }
|
||||||
|
|
||||||
|
indifferent_hash.merge! request.params
|
||||||
|
route_params.each {|k,v| indifferent_hash[k.to_s] = v }
|
||||||
|
|
||||||
|
indifferent_hash
|
||||||
end
|
end
|
||||||
|
|
||||||
def route_params
|
def route_params
|
||||||
|
@ -27,28 +45,29 @@ module Sidekiq
|
||||||
env[RACK_SESSION]
|
env[RACK_SESSION]
|
||||||
end
|
end
|
||||||
|
|
||||||
def erb(content, options = {})
|
def content_type(type)
|
||||||
b = binding
|
@type = type
|
||||||
|
end
|
||||||
|
|
||||||
if locals = options[:locals]
|
def erb(content, options = {})
|
||||||
locals.each {|k, v| b.local_variable_set(k, v) }
|
if content.kind_of? Symbol
|
||||||
|
content = File.read("#{Web.settings.views}/#{content}.erb")
|
||||||
end
|
end
|
||||||
|
|
||||||
_render { ERB.new(content).result(b) }
|
if @_erb
|
||||||
|
_erb(content, options[:locals])
|
||||||
|
else
|
||||||
|
@_erb = true
|
||||||
|
content = _erb(content, options[:locals])
|
||||||
|
|
||||||
|
_render { content }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def partial(file, locals = {})
|
def render(engine, content, options = {})
|
||||||
ERB.new(File.read "#{Web::VIEWS}/_#{file}.erb").result(binding)
|
raise "Only erb templates are supported" if engine != :erb
|
||||||
end
|
|
||||||
|
|
||||||
def redirect(location)
|
erb(content, options)
|
||||||
[302, { LOCATION => "#{request.base_url}#{root_path}#{location}" }, []]
|
|
||||||
end
|
|
||||||
|
|
||||||
def render(file, locals = {})
|
|
||||||
output = erb(File.read "#{Web::VIEWS}/#{file}.erb", locals: locals)
|
|
||||||
|
|
||||||
[200, TEXT_HTML, [output]]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def json(payload)
|
def json(payload)
|
||||||
|
@ -59,5 +78,13 @@ module Sidekiq
|
||||||
@env = env
|
@env = env
|
||||||
@app = app
|
@app = app
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def _erb(file, locals)
|
||||||
|
locals.each {|k, v| define_singleton_method(k){ v } } if locals
|
||||||
|
|
||||||
|
ERB.new(file).result(binding)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,20 +4,25 @@ module Sidekiq
|
||||||
class WebApplication
|
class WebApplication
|
||||||
extend WebRouter
|
extend WebRouter
|
||||||
|
|
||||||
|
CONTENT_TYPE = "Content-Type".freeze
|
||||||
REDIS_KEYS = %w(redis_version uptime_in_days connected_clients used_memory_human used_memory_peak_human)
|
REDIS_KEYS = %w(redis_version uptime_in_days connected_clients used_memory_human used_memory_peak_human)
|
||||||
NOPE = [404, {}, []]
|
NOPE = [404, {}, []]
|
||||||
|
|
||||||
|
def self.settings
|
||||||
|
Web.settings
|
||||||
|
end
|
||||||
|
|
||||||
get "/" do
|
get "/" do
|
||||||
@redis_info = redis_info.select{ |k, v| REDIS_KEYS.include? k }
|
@redis_info = redis_info.select{ |k, v| REDIS_KEYS.include? k }
|
||||||
stats_history = Sidekiq::Stats::History.new((params['days'] || 30).to_i)
|
stats_history = Sidekiq::Stats::History.new((params['days'] || 30).to_i)
|
||||||
@processed_history = stats_history.processed
|
@processed_history = stats_history.processed
|
||||||
@failed_history = stats_history.failed
|
@failed_history = stats_history.failed
|
||||||
|
|
||||||
render(:dashboard)
|
erb(:dashboard)
|
||||||
end
|
end
|
||||||
|
|
||||||
get "/busy" do
|
get "/busy" do
|
||||||
render(:busy)
|
erb(:busy)
|
||||||
end
|
end
|
||||||
|
|
||||||
post "/busy" do
|
post "/busy" do
|
||||||
|
@ -32,39 +37,39 @@ module Sidekiq
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect "busy"
|
redirect "#{root_path}busy"
|
||||||
end
|
end
|
||||||
|
|
||||||
get "/queues" do
|
get "/queues" do
|
||||||
@queues = Sidekiq::Queue.all
|
@queues = Sidekiq::Queue.all
|
||||||
|
|
||||||
render(:queues)
|
erb(:queues)
|
||||||
end
|
end
|
||||||
|
|
||||||
get "/queues/:name" do
|
get "/queues/:name" do
|
||||||
@name = route_params[:name]
|
@name = route_params[:name]
|
||||||
|
|
||||||
next(NOPE) unless @name
|
halt(404) unless @name
|
||||||
|
|
||||||
@count = (params['count'] || 25).to_i
|
@count = (params['count'] || 25).to_i
|
||||||
@queue = Sidekiq::Queue.new(@name)
|
@queue = Sidekiq::Queue.new(@name)
|
||||||
(@current_page, @total_size, @messages) = page("queue:#{@name}", params['page'], @count)
|
(@current_page, @total_size, @messages) = page("queue:#{@name}", params['page'], @count)
|
||||||
@messages = @messages.map { |msg| Sidekiq::Job.new(msg, @name) }
|
@messages = @messages.map { |msg| Sidekiq::Job.new(msg, @name) }
|
||||||
|
|
||||||
render(:queue)
|
erb(:queue)
|
||||||
end
|
end
|
||||||
|
|
||||||
post "/queues/:name" do
|
post "/queues/:name" do
|
||||||
Sidekiq::Queue.new(route_params[:name]).clear
|
Sidekiq::Queue.new(route_params[:name]).clear
|
||||||
|
|
||||||
redirect "queues"
|
redirect "#{root_path}queues"
|
||||||
end
|
end
|
||||||
|
|
||||||
post "/queues/:name/delete" do
|
post "/queues/:name/delete" do
|
||||||
name = route_params[:name]
|
name = route_params[:name]
|
||||||
Sidekiq::Job.new(params['key_val'], name).delete
|
Sidekiq::Job.new(params['key_val'], name).delete
|
||||||
|
|
||||||
redirect_with_query("queues/#{name}")
|
redirect_with_query("#{root_path}queues/#{name}")
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/morgue' do
|
get '/morgue' do
|
||||||
|
@ -72,51 +77,51 @@ module Sidekiq
|
||||||
(@current_page, @total_size, @dead) = page("dead", params['page'], @count, reverse: true)
|
(@current_page, @total_size, @dead) = page("dead", params['page'], @count, reverse: true)
|
||||||
@dead = @dead.map { |msg, score| Sidekiq::SortedEntry.new(nil, score, msg) }
|
@dead = @dead.map { |msg, score| Sidekiq::SortedEntry.new(nil, score, msg) }
|
||||||
|
|
||||||
render(:morgue)
|
erb(:morgue)
|
||||||
end
|
end
|
||||||
|
|
||||||
get "/morgue/:key" do
|
get "/morgue/:key" do
|
||||||
next NOPE unless key = route_params[:key]
|
halt(404) unless key = route_params[:key]
|
||||||
|
|
||||||
@dead = Sidekiq::DeadSet.new.fetch(*parse_params(key)).first
|
@dead = Sidekiq::DeadSet.new.fetch(*parse_params(key)).first
|
||||||
|
|
||||||
if @dead.nil?
|
if @dead.nil?
|
||||||
redirect "morgue"
|
redirect "#{root_path}morgue"
|
||||||
else
|
else
|
||||||
render(:dead)
|
erb(:dead)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
post '/morgue' do
|
post '/morgue' do
|
||||||
next redirect(request.path) unless params['key']
|
redirect(request.path) unless params['key']
|
||||||
|
|
||||||
params['key'].each do |key|
|
params['key'].each do |key|
|
||||||
job = Sidekiq::DeadSet.new.fetch(*parse_params(key)).first
|
job = Sidekiq::DeadSet.new.fetch(*parse_params(key)).first
|
||||||
retry_or_delete_or_kill job, params if job
|
retry_or_delete_or_kill job, params if job
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect_with_query("morgue")
|
redirect_with_query("#{root_path}morgue")
|
||||||
end
|
end
|
||||||
|
|
||||||
post "/morgue/all/delete" do
|
post "/morgue/all/delete" do
|
||||||
Sidekiq::DeadSet.new.clear
|
Sidekiq::DeadSet.new.clear
|
||||||
|
|
||||||
redirect "morgue"
|
redirect "#{root_path}morgue"
|
||||||
end
|
end
|
||||||
|
|
||||||
post "/morgue/all/retry" do
|
post "/morgue/all/retry" do
|
||||||
Sidekiq::DeadSet.new.retry_all
|
Sidekiq::DeadSet.new.retry_all
|
||||||
|
|
||||||
redirect "morgue"
|
redirect "#{root_path}morgue"
|
||||||
end
|
end
|
||||||
|
|
||||||
post "/morgue/:key" do
|
post "/morgue/:key" do
|
||||||
next NOPE unless key = route_params[:key]
|
halt(404) unless key = route_params[:key]
|
||||||
|
|
||||||
job = Sidekiq::DeadSet.new.fetch(*parse_params(key)).first
|
job = Sidekiq::DeadSet.new.fetch(*parse_params(key)).first
|
||||||
retry_or_delete_or_kill job, params if job
|
retry_or_delete_or_kill job, params if job
|
||||||
|
|
||||||
redirect_with_query("morgue")
|
redirect_with_query("#{root_path}morgue")
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/retries' do
|
get '/retries' do
|
||||||
|
@ -124,40 +129,40 @@ module Sidekiq
|
||||||
(@current_page, @total_size, @retries) = page("retry", params['page'], @count)
|
(@current_page, @total_size, @retries) = page("retry", params['page'], @count)
|
||||||
@retries = @retries.map { |msg, score| Sidekiq::SortedEntry.new(nil, score, msg) }
|
@retries = @retries.map { |msg, score| Sidekiq::SortedEntry.new(nil, score, msg) }
|
||||||
|
|
||||||
render(:retries)
|
erb(:retries)
|
||||||
end
|
end
|
||||||
|
|
||||||
get "/retries/:key" do
|
get "/retries/:key" do
|
||||||
@retry = Sidekiq::RetrySet.new.fetch(*parse_params(route_params[:key])).first
|
@retry = Sidekiq::RetrySet.new.fetch(*parse_params(route_params[:key])).first
|
||||||
|
|
||||||
if @retry.nil?
|
if @retry.nil?
|
||||||
redirect "retries"
|
redirect "#{root_path}retries"
|
||||||
else
|
else
|
||||||
render(:retry)
|
erb(:retry)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
post '/retries' do
|
post '/retries' do
|
||||||
next redirect(request.path) unless params['key']
|
redirect(request.path) unless params['key']
|
||||||
|
|
||||||
params['key'].each do |key|
|
params['key'].each do |key|
|
||||||
job = Sidekiq::RetrySet.new.fetch(*parse_params(key)).first
|
job = Sidekiq::RetrySet.new.fetch(*parse_params(key)).first
|
||||||
retry_or_delete_or_kill job, params if job
|
retry_or_delete_or_kill job, params if job
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect_with_query("retries")
|
redirect_with_query("#{root_path}retries")
|
||||||
end
|
end
|
||||||
|
|
||||||
post "/retries/all/delete" do
|
post "/retries/all/delete" do
|
||||||
Sidekiq::RetrySet.new.clear
|
Sidekiq::RetrySet.new.clear
|
||||||
|
|
||||||
redirect "retries"
|
redirect "#{root_path}retries"
|
||||||
end
|
end
|
||||||
|
|
||||||
post "/retries/all/retry" do
|
post "/retries/all/retry" do
|
||||||
Sidekiq::RetrySet.new.retry_all
|
Sidekiq::RetrySet.new.retry_all
|
||||||
|
|
||||||
redirect "retries"
|
redirect "#{root_path}retries"
|
||||||
end
|
end
|
||||||
|
|
||||||
post "/retries/:key" do
|
post "/retries/:key" do
|
||||||
|
@ -165,7 +170,7 @@ module Sidekiq
|
||||||
|
|
||||||
retry_or_delete_or_kill job, params if job
|
retry_or_delete_or_kill job, params if job
|
||||||
|
|
||||||
redirect_with_query("retries")
|
redirect_with_query("#{root_path}retries")
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/scheduled' do
|
get '/scheduled' do
|
||||||
|
@ -173,41 +178,41 @@ module Sidekiq
|
||||||
(@current_page, @total_size, @scheduled) = page("schedule", params['page'], @count)
|
(@current_page, @total_size, @scheduled) = page("schedule", params['page'], @count)
|
||||||
@scheduled = @scheduled.map { |msg, score| Sidekiq::SortedEntry.new(nil, score, msg) }
|
@scheduled = @scheduled.map { |msg, score| Sidekiq::SortedEntry.new(nil, score, msg) }
|
||||||
|
|
||||||
render(:scheduled)
|
erb(:scheduled)
|
||||||
end
|
end
|
||||||
|
|
||||||
get "/scheduled/:key" do
|
get "/scheduled/:key" do
|
||||||
@job = Sidekiq::ScheduledSet.new.fetch(*parse_params(route_params[:key])).first
|
@job = Sidekiq::ScheduledSet.new.fetch(*parse_params(route_params[:key])).first
|
||||||
|
|
||||||
if @job.nil?
|
if @job.nil?
|
||||||
redirect "scheduled"
|
redirect "#{root_path}scheduled"
|
||||||
else
|
else
|
||||||
render(:scheduled_job_info)
|
erb(:scheduled_job_info)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
post '/scheduled' do
|
post '/scheduled' do
|
||||||
next redirect(request.path) unless params['key']
|
redirect(request.path) unless params['key']
|
||||||
|
|
||||||
params['key'].each do |key|
|
params['key'].each do |key|
|
||||||
job = Sidekiq::ScheduledSet.new.fetch(*parse_params(key)).first
|
job = Sidekiq::ScheduledSet.new.fetch(*parse_params(key)).first
|
||||||
delete_or_add_queue job, params if job
|
delete_or_add_queue job, params if job
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect_with_query("scheduled")
|
redirect_with_query("#{root_path}scheduled")
|
||||||
end
|
end
|
||||||
|
|
||||||
post "/scheduled/:key" do
|
post "/scheduled/:key" do
|
||||||
next NOPE unless key = route_params[:key]
|
halt(404) unless key = route_params[:key]
|
||||||
|
|
||||||
job = Sidekiq::ScheduledSet.new.fetch(*parse_params(key)).first
|
job = Sidekiq::ScheduledSet.new.fetch(*parse_params(key)).first
|
||||||
delete_or_add_queue job, params if job
|
delete_or_add_queue job, params if job
|
||||||
|
|
||||||
redirect_with_query("scheduled")
|
redirect_with_query("#{root_path}scheduled")
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/dashboard/stats' do
|
get '/dashboard/stats' do
|
||||||
redirect "stats"
|
redirect "#{root_path}stats"
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/stats' do
|
get '/stats' do
|
||||||
|
@ -238,42 +243,60 @@ module Sidekiq
|
||||||
action = self.class.match(env)
|
action = self.class.match(env)
|
||||||
return NOPE unless action
|
return NOPE unless action
|
||||||
|
|
||||||
self.class.run_befores(env)
|
resp = catch(:halt) do
|
||||||
resp = action.instance_exec env, &action.app
|
self.class.run_befores(action)
|
||||||
self.class.run_afters(env)
|
resp = action.instance_exec env, &action.app
|
||||||
|
self.class.run_afters(action)
|
||||||
|
|
||||||
|
resp
|
||||||
|
end
|
||||||
|
|
||||||
case resp
|
case resp
|
||||||
when Array
|
when Array
|
||||||
resp
|
resp
|
||||||
when Integer
|
when Fixnum
|
||||||
[resp, {}, []]
|
[resp, {}, []]
|
||||||
else
|
else
|
||||||
[200, WebAction::TEXT_HTML, [resp]]
|
headers = case action.type
|
||||||
|
when :json
|
||||||
|
WebAction::APPLICATION_JSON
|
||||||
|
when String
|
||||||
|
{ WebAction::CONTENT_TYPE => action.type }
|
||||||
|
else
|
||||||
|
WebAction::TEXT_HTML
|
||||||
|
end
|
||||||
|
|
||||||
|
[200, headers, [resp]]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.helpers(mod)
|
def self.helpers(mod=nil, &block)
|
||||||
WebAction.send(:include, mod)
|
if block_given?
|
||||||
end
|
WebAction.class_eval(&block)
|
||||||
|
else
|
||||||
def self.before(&block)
|
WebAction.send(:include, mod)
|
||||||
befores << block
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.after(&block)
|
|
||||||
afters << block
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.run_befores(env)
|
|
||||||
befores.each do |b|
|
|
||||||
b.call(env)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.run_afters(env)
|
def self.before(path=nil, &block)
|
||||||
afters.each do |b|
|
befores << [path && Regexp.new("\\A#{path.gsub("*", ".*")}\\z"), block]
|
||||||
b.call(env)
|
end
|
||||||
end
|
|
||||||
|
def self.after(path=nil, &block)
|
||||||
|
afters << [path && Regexp.new("\\A#{path.gsub("*", ".*")}\\z"), block]
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.run_befores(action)
|
||||||
|
run_hooks(befores, action)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.run_afters(action)
|
||||||
|
run_hooks(afters, action)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.run_hooks(hooks, action)
|
||||||
|
hooks.select { |p,_| !p || p =~ action.env[WebRouter::PATH_INFO] }.
|
||||||
|
each {|_,b| action.instance_exec(action.env, &b) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.befores
|
def self.befores
|
||||||
|
|
|
@ -10,7 +10,7 @@ module Sidekiq
|
||||||
@@strings[lang] ||= begin
|
@@strings[lang] ||= begin
|
||||||
# Allow sidekiq-web extensions to add locale paths
|
# Allow sidekiq-web extensions to add locale paths
|
||||||
# so extensions can be localized
|
# so extensions can be localized
|
||||||
Web.locales.each_with_object({}) do |path, global|
|
settings.locales.each_with_object({}) do |path, global|
|
||||||
find_locale_files(lang).each do |file|
|
find_locale_files(lang).each do |file|
|
||||||
strs = YAML.load(File.open(file))
|
strs = YAML.load(File.open(file))
|
||||||
global.deep_merge!(strs[lang])
|
global.deep_merge!(strs[lang])
|
||||||
|
@ -25,7 +25,7 @@ module Sidekiq
|
||||||
end
|
end
|
||||||
|
|
||||||
def locale_files
|
def locale_files
|
||||||
@@locale_files ||= Web.locales.flat_map do |path|
|
@@locale_files ||= settings.locales.flat_map do |path|
|
||||||
Dir["#{path}/*.yml"]
|
Dir["#{path}/*.yml"]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -46,21 +46,13 @@ module Sidekiq
|
||||||
# <meta .../>
|
# <meta .../>
|
||||||
# <% end %>
|
# <% end %>
|
||||||
#
|
#
|
||||||
def add_to_head(&block)
|
def add_to_head
|
||||||
@head_html ||= []
|
@head_html ||= []
|
||||||
@head_html << block if block_given?
|
@head_html << yield.dup if block_given?
|
||||||
end
|
end
|
||||||
|
|
||||||
def display_custom_head
|
def display_custom_head
|
||||||
return unless defined?(@head_html)
|
@head_html.join if @head_html
|
||||||
@head_html.map { |block| capture(&block) }.join
|
|
||||||
end
|
|
||||||
|
|
||||||
# Simple capture method for erb templates. The origin was
|
|
||||||
# capture method from sinatra-contrib library.
|
|
||||||
def capture(&block)
|
|
||||||
block.call
|
|
||||||
eval('', block.binding)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Given a browser request Accept-Language header like
|
# Given a browser request Accept-Language header like
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
module Sidekiq
|
module Sidekiq
|
||||||
module WebRouter
|
module WebRouter
|
||||||
GET = 'GET'.freeze
|
GET = 'GET'.freeze
|
||||||
|
DELETE = 'DELETE'.freeze
|
||||||
POST = 'POST'.freeze
|
POST = 'POST'.freeze
|
||||||
HEAD = 'HEAD'.freeze
|
HEAD = 'HEAD'.freeze
|
||||||
|
|
||||||
|
@ -18,6 +19,10 @@ module Sidekiq
|
||||||
route(POST, path, &block)
|
route(POST, path, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def delete(path, &block)
|
||||||
|
route(DELETE, path, &block)
|
||||||
|
end
|
||||||
|
|
||||||
def route(method, path, &block)
|
def route(method, path, &block)
|
||||||
@routes ||= []
|
@routes ||= []
|
||||||
@routes << WebRoute.new(method, path, block)
|
@routes << WebRoute.new(method, path, block)
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
require_relative 'helper'
|
require_relative 'helper'
|
||||||
require 'sidekiq/web'
|
require 'sidekiq/web'
|
||||||
require 'rack/test'
|
require 'rack/test'
|
||||||
#require 'tilt/erubis'
|
|
||||||
|
|
||||||
class TestWeb < Sidekiq::Test
|
class TestWeb < Sidekiq::Test
|
||||||
|
|
||||||
|
@ -371,18 +370,17 @@ class TestWeb < Sidekiq::Test
|
||||||
|
|
||||||
describe 'custom locales' do
|
describe 'custom locales' do
|
||||||
before do
|
before do
|
||||||
Sidekiq::Web.locales << File.join(File.dirname(__FILE__), "fixtures")
|
Sidekiq::Web.settings.locales << File.join(File.dirname(__FILE__), "fixtures")
|
||||||
Sidekiq::Web.tabs['Custom Tab'] = '/custom'
|
Sidekiq::Web.tabs['Custom Tab'] = '/custom'
|
||||||
Sidekiq::WebApplication.get('/custom') do
|
Sidekiq::WebApplication.get('/custom') do
|
||||||
clear_caches # ugly hack since I can't figure out how to access WebHelpers outside of this context
|
clear_caches # ugly hack since I can't figure out how to access WebHelpers outside of this context
|
||||||
|
t('translated_text')
|
||||||
[200, { "Content-Type" => 'text/html' }, [ t('translated_text') ]]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
after do
|
after do
|
||||||
Sidekiq::Web.tabs.delete 'Custom Tab'
|
Sidekiq::Web.tabs.delete 'Custom Tab'
|
||||||
Sidekiq::Web.locales.pop
|
Sidekiq::Web.settings.locales.pop
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can show user defined tab with custom locales' do
|
it 'can show user defined tab with custom locales' do
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
<% job = locals[:job] %>
|
|
||||||
|
|
||||||
<header>
|
<header>
|
||||||
<h3><%= t('Job') %></h3>
|
<h3><%= t('Job') %></h3>
|
||||||
</header>
|
</header>
|
||||||
|
@ -52,7 +50,7 @@
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if locals[:type] == :retry %>
|
<% if type == :retry %>
|
||||||
<% if job['retry_count'] && job['retry_count'] > 0 %>
|
<% if job['retry_count'] && job['retry_count'] > 0 %>
|
||||||
<tr>
|
<tr>
|
||||||
<th><%= t('RetryCount') %></th>
|
<th><%= t('RetryCount') %></th>
|
||||||
|
@ -73,13 +71,13 @@
|
||||||
<td><%= relative_time(job.at) %></td>
|
<td><%= relative_time(job.at) %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if locals[:type] == :scheduled %>
|
<% if type == :scheduled %>
|
||||||
<tr>
|
<tr>
|
||||||
<th><%= t('Scheduled') %></th>
|
<th><%= t('Scheduled') %></th>
|
||||||
<td><%= relative_time(job.at) %></td>
|
<td><%= relative_time(job.at) %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if locals[:type] == :dead %>
|
<% if type == :dead %>
|
||||||
<tr>
|
<tr>
|
||||||
<th><%= t('LastRetry') %></th>
|
<th><%= t('LastRetry') %></th>
|
||||||
<td><%= relative_time(job.at) %></td>
|
<td><%= relative_time(job.at) %></td>
|
||||||
|
|
|
@ -7,14 +7,14 @@
|
||||||
<span class="icon-bar"></span>
|
<span class="icon-bar"></span>
|
||||||
</button>
|
</button>
|
||||||
<div class="navbar-toggle collapsed navbar-livereload">
|
<div class="navbar-toggle collapsed navbar-livereload">
|
||||||
<%= partial :poll_link %>
|
<%= erb :_poll_link %>
|
||||||
<% if Sidekiq::Web.app_url %>
|
<% if Sidekiq::Web.app_url %>
|
||||||
<a class="btn btn-inverse" href="<%= Sidekiq::Web.app_url %>">Back to App</a>
|
<a class="btn btn-inverse" href="<%= Sidekiq::Web.app_url %>">Back to App</a>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<a class="navbar-brand" href="<%= root_path %>">
|
<a class="navbar-brand" href="<%= root_path %>">
|
||||||
<%= Sidekiq::NAME %>
|
<%= Sidekiq::NAME %>
|
||||||
<%= partial :status %>
|
<%= erb :_status %>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@
|
||||||
<ul class="nav navbar-nav navbar-right navbar-livereload" data-navbar="static">
|
<ul class="nav navbar-nav navbar-right navbar-livereload" data-navbar="static">
|
||||||
<li>
|
<li>
|
||||||
<div class="poll-wrapper pull-right">
|
<div class="poll-wrapper pull-right">
|
||||||
<%= partial :poll_link %>
|
<%= erb :_poll_link %>
|
||||||
<% if Sidekiq::Web.app_url %>
|
<% if Sidekiq::Web.app_url %>
|
||||||
<a class="btn btn-inverse" href="<%= Sidekiq::Web.app_url %>"><%= t('BackToApp') %></a>
|
<a class="btn btn-inverse" href="<%= Sidekiq::Web.app_url %>"><%= t('BackToApp') %></a>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -1,23 +1,23 @@
|
||||||
<% if @total_size > @count %>
|
<% if @total_size > @count %>
|
||||||
<ul class="pagination pull-right">
|
<ul class="pagination pull-right">
|
||||||
<li class="<%= 'disabled' if @current_page == 1 %>">
|
<li class="<%= 'disabled' if @current_page == 1 %>">
|
||||||
<a href="<%= locals[:url] %>?page=1">«</a>
|
<a href="<%= url %>?page=1">«</a>
|
||||||
</li>
|
</li>
|
||||||
<% if @current_page > 1 %>
|
<% if @current_page > 1 %>
|
||||||
<li>
|
<li>
|
||||||
<a href="<%= locals[:url] %>?<%= qparams(page: @current_page - 1) %>"><%= @current_page - 1 %></a>
|
<a href="<%= url %>?<%= qparams(page: @current_page - 1) %>"><%= @current_page - 1 %></a>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
<li class="disabled">
|
<li class="disabled">
|
||||||
<a href="<%= locals[:url] %>?<%= qparams(page: @current_page) %>"><%= @current_page %></a>
|
<a href="<%= url %>?<%= qparams(page: @current_page) %>"><%= @current_page %></a>
|
||||||
</li>
|
</li>
|
||||||
<% if @total_size > @current_page * @count %>
|
<% if @total_size > @current_page * @count %>
|
||||||
<li>
|
<li>
|
||||||
<a href="<%= locals[:url] %>?<%= qparams(page: @current_page + 1) %>"><%= @current_page + 1 %></a>
|
<a href="<%= url %>?<%= qparams(page: @current_page + 1) %>"><%= @current_page + 1 %></a>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
<li class="<%= 'disabled' if @total_size <= @current_page * @count %>">
|
<li class="<%= 'disabled' if @total_size <= @current_page * @count %>">
|
||||||
<a href="<%= locals[:url] %>?<%= qparams(page: (@total_size.to_f / @count).ceil) %>">»</a>
|
<a href="<%= url %>?<%= qparams(page: (@total_size.to_f / @count).ceil) %>">»</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<% if current_path != '' && params['poll'] %>
|
<% if current_path != '' && params[:poll] %>
|
||||||
<script>
|
<script>
|
||||||
updatePage('<%= root_path + current_path %>')
|
updatePage('<%= root_path + current_path %>')
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<% if current_path != '' %>
|
<% if current_path != '' %>
|
||||||
<% if params['poll'] %>
|
<% if params[:poll] %>
|
||||||
<a id="live-poll" class="btn btn-primary active" href="<%= root_path + current_path %>"><%= t('StopPolling') %></a>
|
<a id="live-poll" class="btn btn-primary active" href="<%= root_path + current_path %>"><%= t('StopPolling') %></a>
|
||||||
<% else %>
|
<% else %>
|
||||||
<a id="live-poll" class="btn btn-primary" href="<%= root_path + current_path %>?<%= qparams(poll: true) %>"><%= t('LivePoll') %></a>
|
<a id="live-poll" class="btn btn-primary" href="<%= root_path + current_path %>?<%= qparams(poll: true) %>"><%= t('LivePoll') %></a>
|
||||||
|
|
|
@ -23,10 +23,10 @@
|
||||||
<div class="row chart">
|
<div class="row chart">
|
||||||
<h5>
|
<h5>
|
||||||
<span class="history-heading"><%= t('History') %></span>
|
<span class="history-heading"><%= t('History') %></span>
|
||||||
<a href="<%= root_path %>?days=7" class="history-graph <%= "active" if params['days'] == "7" %>"><%= t('OneWeek') %></a>
|
<a href="<%= root_path %>?days=7" class="history-graph <%= "active" if params[:days] == "7" %>"><%= t('OneWeek') %></a>
|
||||||
<a href="<%= root_path %>" class="history-graph <%= "active" if params['days'].nil? || params['days'] == "30" %>"><%= t('OneMonth') %></a>
|
<a href="<%= root_path %>" class="history-graph <%= "active" if params[:days].nil? || params[:days] == "30" %>"><%= t('OneMonth') %></a>
|
||||||
<a href="<%= root_path %>?days=90" class="history-graph <%= "active" if params['days'] == "90" %>"><%= t('ThreeMonths') %></a>
|
<a href="<%= root_path %>?days=90" class="history-graph <%= "active" if params[:days] == "90" %>"><%= t('ThreeMonths') %></a>
|
||||||
<a href="<%= root_path %>?days=180" class="history-graph <%= "active" if params['days'] == "180" %>"><%= t('SixMonths') %></a>
|
<a href="<%= root_path %>?days=180" class="history-graph <%= "active" if params[:days] == "180" %>"><%= t('SixMonths') %></a>
|
||||||
</h5>
|
</h5>
|
||||||
|
|
||||||
<div id="history" data-processed-label="<%= t('Processed') %>" data-failed-label="<%= t('Failed') %>" data-processed="<%= h Sidekiq.dump_json(@processed_history) %>" data-failed="<%= h Sidekiq.dump_json(@failed_history) %>" data-update-url="<%= root_path %>stats"></div>
|
<div id="history" data-processed-label="<%= t('Processed') %>" data-failed-label="<%= t('Failed') %>" data-processed="<%= h Sidekiq.dump_json(@processed_history) %>" data-failed="<%= h Sidekiq.dump_json(@failed_history) %>" data-update-url="<%= root_path %>stats"></div>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<%= partial :job_info, job: @dead, type: :dead %>
|
<%= erb :_job_info, locals: { job: @dead, type: :dead } %>
|
||||||
|
|
||||||
<h3><%= t('Error') %></h3>
|
<h3><%= t('Error') %></h3>
|
||||||
<div class="table_container">
|
<div class="table_container">
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title><%= environment_title_prefix %><%= Sidekiq::NAME %></title>
|
<title><%= environment_title_prefix %><%= Sidekiq::NAME %></title>
|
||||||
|
<meta charset="utf8" />
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
|
||||||
<link href="<%= root_path %>stylesheets/bootstrap.css" media="screen" rel="stylesheet" type="text/css" />
|
<link href="<%= root_path %>stylesheets/bootstrap.css" media="screen" rel="stylesheet" type="text/css" />
|
||||||
<link href="<%= root_path %>stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />
|
<link href="<%= root_path %>stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />
|
||||||
|
@ -12,12 +13,12 @@
|
||||||
<%= display_custom_head %>
|
<%= display_custom_head %>
|
||||||
</head>
|
</head>
|
||||||
<body class="admin">
|
<body class="admin">
|
||||||
<%= partial :nav %>
|
<%= erb :_nav %>
|
||||||
<div id="page">
|
<div id="page">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-12 summary_bar">
|
<div class="col-sm-12 summary_bar">
|
||||||
<%= partial :summary %>
|
<%= erb :_summary %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-sm-12">
|
<div class="col-sm-12">
|
||||||
|
@ -26,7 +27,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<%= partial :footer %>
|
<%= erb :_footer %>
|
||||||
<%= partial :poll_js %>
|
<%= erb :_poll_js %>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
</div>
|
</div>
|
||||||
<% if @dead.size > 0 && @total_size > @count %>
|
<% if @dead.size > 0 && @total_size > @count %>
|
||||||
<div class="col-sm-4">
|
<div class="col-sm-4">
|
||||||
<%= partial :paging, url: "#{root_path}morgue" %>
|
<%= erb :_paging, locals: { url: "#{root_path}morgue" } %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= filtering('dead') %>
|
<%= filtering('dead') %>
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-4 pull-right">
|
<div class="col-sm-4 pull-right">
|
||||||
<%= partial :paging, url: "#{root_path}queues/#{@name}" %>
|
<%= erb :_paging, locals: { url: "#{root_path}queues/#{@name}" } %>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
<div class="table_container">
|
<div class="table_container">
|
||||||
|
@ -42,4 +42,4 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<%= partial :paging, url: "#{root_path}queues/#{@name}" %>
|
<%= erb :_paging, locals: { url: "#{root_path}queues/#{@name}" } %>
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
</div>
|
</div>
|
||||||
<% if @retries.size > 0 && @total_size > @count %>
|
<% if @retries.size > 0 && @total_size > @count %>
|
||||||
<div class="col-sm-4">
|
<div class="col-sm-4">
|
||||||
<%= partial :paging, url: "#{root_path}retries" %>
|
<%= erb :_paging, locals: { url: "#{root_path}retries" } %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= filtering('retries') %>
|
<%= filtering('retries') %>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<%= partial :job_info, job: @retry, type: :retry %>
|
<%= erb :_job_info, locals: { job: @retry, type: :retry } %>
|
||||||
|
|
||||||
<h3><%= t('Error') %></h3>
|
<h3><%= t('Error') %></h3>
|
||||||
<div class="table_container">
|
<div class="table_container">
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
</div>
|
</div>
|
||||||
<% if @scheduled.size > 0 && @total_size > @count %>
|
<% if @scheduled.size > 0 && @total_size > @count %>
|
||||||
<div class="col-sm-4">
|
<div class="col-sm-4">
|
||||||
<%= partial :paging, url: "#{root_path}scheduled" %>
|
<%= erb :_paging, locals: { url: "#{root_path}scheduled" } %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= filtering('scheduled') %>
|
<%= filtering('scheduled') %>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<%= partial :job_info, job: @job, type: :scheduled %>
|
<%= erb :_job_info, locals: { job: @job, type: :scheduled } %>
|
||||||
|
|
||||||
<form class="form-horizontal" action="<%= root_path %>scheduled/<%= job_params(@job, @job.score) %>" method="post">
|
<form class="form-horizontal" action="<%= root_path %>scheduled/<%= job_params(@job, @job.score) %>" method="post">
|
||||||
<%= csrf_tag %>
|
<%= csrf_tag %>
|
||||||
|
|
Loading…
Add table
Reference in a new issue