2015-12-31 18:33:35 -05:00
|
|
|
# frozen_string_literal: true
|
2013-05-16 11:27:10 -04:00
|
|
|
|
2019-04-01 12:20:41 -04:00
|
|
|
require "erb"
|
2012-07-18 01:14:15 -04:00
|
|
|
|
2019-04-01 12:20:41 -04:00
|
|
|
require "sidekiq"
|
|
|
|
require "sidekiq/api"
|
|
|
|
require "sidekiq/paginator"
|
|
|
|
require "sidekiq/web/helpers"
|
2016-07-26 10:03:17 -04:00
|
|
|
|
2019-04-01 12:20:41 -04:00
|
|
|
require "sidekiq/web/router"
|
|
|
|
require "sidekiq/web/action"
|
|
|
|
require "sidekiq/web/application"
|
2020-06-03 19:06:36 -04:00
|
|
|
require "sidekiq/web/csrf_protection"
|
2012-07-18 01:14:15 -04:00
|
|
|
|
2020-04-22 17:03:50 -04:00
|
|
|
require "rack/content_length"
|
2019-04-01 12:20:41 -04:00
|
|
|
require "rack/builder"
|
2021-03-12 19:03:36 -05:00
|
|
|
require "rack/static"
|
2015-07-06 15:51:15 -04:00
|
|
|
|
2016-07-26 10:03:17 -04:00
|
|
|
module Sidekiq
|
|
|
|
class Web
|
2016-07-27 15:18:52 -04:00
|
|
|
ROOT = File.expand_path("#{File.dirname(__FILE__)}/../../web")
|
2018-02-16 16:11:54 -05:00
|
|
|
VIEWS = "#{ROOT}/views"
|
|
|
|
LOCALES = ["#{ROOT}/locales"]
|
|
|
|
LAYOUT = "#{VIEWS}/layout.erb"
|
|
|
|
ASSETS = "#{ROOT}/assets"
|
2012-03-06 23:17:42 -05:00
|
|
|
|
2013-10-13 18:56:17 -04:00
|
|
|
DEFAULT_TABS = {
|
2019-04-01 12:20:41 -04:00
|
|
|
"Dashboard" => "",
|
|
|
|
"Busy" => "busy",
|
|
|
|
"Queues" => "queues",
|
|
|
|
"Retries" => "retries",
|
|
|
|
"Scheduled" => "scheduled",
|
2020-03-17 16:38:48 -04: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
|
2016-07-28 22:36:21 -04:00
|
|
|
def settings
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2013-10-13 18:56:17 -04:00
|
|
|
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
|
2014-08-01 19:40:42 -04:00
|
|
|
|
2016-07-26 10:03:17 -04:00
|
|
|
def locales
|
|
|
|
@locales ||= LOCALES
|
2014-05-16 00:12:44 -04:00
|
|
|
end
|
2012-05-02 23:19:59 -04:00
|
|
|
|
2016-07-28 22:36:21 -04:00
|
|
|
def views
|
|
|
|
@views ||= VIEWS
|
|
|
|
end
|
|
|
|
|
2016-10-14 12:51:13 -04:00
|
|
|
def enable(*opts)
|
2019-05-30 13:41:47 -04:00
|
|
|
opts.each { |key| set(key, true) }
|
2016-10-14 12:51:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def disable(*opts)
|
2019-05-30 13:41:47 -04:00
|
|
|
opts.each { |key| set(key, false) }
|
2016-10-14 12:51:13 -04:00
|
|
|
end
|
|
|
|
|
2021-02-21 14:59:01 -05:00
|
|
|
def middlewares
|
|
|
|
@middlewares ||= []
|
|
|
|
end
|
|
|
|
|
|
|
|
def use(*args, &block)
|
|
|
|
middlewares << [args, block]
|
|
|
|
end
|
|
|
|
|
2016-09-15 10:19:46 -04:00
|
|
|
def set(attribute, value)
|
|
|
|
send(:"#{attribute}=", value)
|
|
|
|
end
|
|
|
|
|
2021-02-12 17:50:51 -05:00
|
|
|
def sessions=(val)
|
|
|
|
puts "WARNING: Sidekiq::Web.sessions= is no longer relevant and will be removed in Sidekiq 7.0. #{caller(1..1).first}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def session_secret=(val)
|
|
|
|
puts "WARNING: Sidekiq::Web.session_secret= is no longer relevant and will be removed in Sidekiq 7.0. #{caller(1..1).first}"
|
|
|
|
end
|
|
|
|
|
|
|
|
attr_accessor :app_url, :redis_pool
|
2016-07-28 22:36:21 -04:00
|
|
|
attr_writer :locales, :views
|
|
|
|
end
|
|
|
|
|
2016-10-17 14:16:26 -04:00
|
|
|
def self.inherited(child)
|
2019-04-01 12:20:41 -04:00
|
|
|
child.app_url = app_url
|
|
|
|
child.redis_pool = redis_pool
|
2016-10-17 14:16:26 -04:00
|
|
|
end
|
|
|
|
|
2016-07-28 22:36:21 -04:00
|
|
|
def settings
|
|
|
|
self.class.settings
|
2014-02-09 17:56:01 -05:00
|
|
|
end
|
|
|
|
|
2021-02-12 17:50:51 -05:00
|
|
|
def middlewares
|
2021-02-21 14:59:01 -05:00
|
|
|
@middlewares ||= self.class.middlewares
|
2016-07-30 16:09:26 -04:00
|
|
|
end
|
|
|
|
|
2021-02-12 17:50:51 -05:00
|
|
|
def use(*args, &block)
|
|
|
|
middlewares << [args, block]
|
2016-07-30 16:09:26 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
|
|
|
app.call(env)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.call(env)
|
|
|
|
@app ||= new
|
|
|
|
@app.call(env)
|
|
|
|
end
|
|
|
|
|
|
|
|
def app
|
|
|
|
@app ||= build
|
|
|
|
end
|
|
|
|
|
2016-10-14 12:51:13 -04:00
|
|
|
def enable(*opts)
|
2019-05-30 13:41:47 -04:00
|
|
|
opts.each { |key| set(key, true) }
|
2016-10-14 12:51:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def disable(*opts)
|
2019-05-30 13:41:47 -04:00
|
|
|
opts.each { |key| set(key, false) }
|
2016-10-14 12:51:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def set(attribute, value)
|
|
|
|
send(:"#{attribute}=", value)
|
|
|
|
end
|
|
|
|
|
2021-02-12 17:50:51 -05:00
|
|
|
def sessions=(val)
|
|
|
|
puts "Sidekiq::Web#sessions= is no longer relevant and will be removed in Sidekiq 7.0. #{caller[2..2].first}"
|
2016-10-14 12:51:13 -04:00
|
|
|
end
|
|
|
|
|
2016-07-30 16:09:26 -04:00
|
|
|
def self.register(extension)
|
|
|
|
extension.registered(WebApplication)
|
|
|
|
end
|
|
|
|
|
2021-02-12 17:50:51 -05:00
|
|
|
private
|
2016-10-14 12:51:13 -04:00
|
|
|
|
|
|
|
def build
|
|
|
|
klass = self.class
|
2021-02-21 14:59:01 -05:00
|
|
|
m = middlewares
|
2016-08-01 19:29:22 -04:00
|
|
|
|
2016-07-30 16:09:26 -04:00
|
|
|
::Rack::Builder.new do
|
2021-03-25 19:17:00 -04:00
|
|
|
use Rack::Static, urls: ["/stylesheets", "/images", "/javascripts"],
|
|
|
|
root: ASSETS,
|
|
|
|
cascade: true,
|
|
|
|
header_rules: [
|
|
|
|
[:all, {"Cache-Control" => "public, max-age=86400"}]
|
2021-03-12 19:03:36 -05:00
|
|
|
]
|
2021-02-12 17:50:51 -05:00
|
|
|
m.each { |middleware, block| use(*middleware, &block) }
|
2021-02-21 14:59:01 -05:00
|
|
|
use Sidekiq::Web::CsrfProtection unless $TESTING
|
2016-07-29 15:09:00 -04:00
|
|
|
run WebApplication.new(klass)
|
2012-11-26 14:53:22 -05:00
|
|
|
end
|
2012-03-29 23:55:16 -04:00
|
|
|
end
|
2012-03-04 15:58:16 -05:00
|
|
|
end
|
2016-07-27 15:18:52 -04:00
|
|
|
|
|
|
|
Sidekiq::WebApplication.helpers WebHelpers
|
|
|
|
Sidekiq::WebApplication.helpers Sidekiq::Paginator
|
|
|
|
|
2019-04-01 12:20:41 -04:00
|
|
|
Sidekiq::WebAction.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
|
|
|
def _render
|
|
|
|
#{ERB.new(File.read(Web::LAYOUT)).src}
|
|
|
|
end
|
|
|
|
RUBY
|
2012-03-04 15:58:16 -05:00
|
|
|
end
|