Class: Sidekiq::Web::Config
- Inherits:
-
Object
- Object
- Sidekiq::Web::Config
- Extended by:
- Forwardable
- Defined in:
- lib/sidekiq/web/config.rb
Overview
Configure the Sidekiq::Web instance in this process:
require "sidekiq/web"
Sidekiq::Web.configure do |config|
config.register(MyExtension, name: "myext", tab: "TabName", index: "tabpage/")
end
This should go in your ‘config/routes.rb` or similar. It does not belong in your initializer since Web should not be loaded in some processes (like an actual Sidekiq process). See `examples/webui-ext` for a sample web extension.
Constant Summary collapse
- OPTIONS =
{ # By default we support direct uploads to p.f.c since the UI is a JS SPA # and very difficult for us to vendor or provide ourselves. If you are worried # about data security and wish to self-host, you can change these URLs. profile_view_url: "https://profiler.firefox.com/public/%s", profile_store_url: "https://api.profiler.firefox.com/compressed-store", # Will be false in Sidekiq 9.0. # CSRF is unnecessary if you are using SameSite=(Strict|Lax) cookies. csrf: true }
Instance Attribute Summary collapse
-
#app_url ⇒ Object
Adds the “Back to App” link in the header.
-
#custom_job_info_rows ⇒ Object
Allows users to add custom rows to all of the Job tables, e.g.
-
#locales ⇒ Object
readonly
Returns the value of attribute locales.
-
#middlewares ⇒ Object
readonly
Returns the value of attribute middlewares.
-
#tabs ⇒ Object
readonly
Returns the value of attribute tabs.
-
#views ⇒ Object
readonly
Returns the value of attribute views.
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
-
#register_extension(extclass, name:, tab:, index:, root_dir: nil, cache_for: 86400, asset_paths: nil) {|_self| ... } ⇒ Object
(also: #register)
Register a class as a Sidekiq Web UI extension.
- #use(*args, &block) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
58 59 60 61 62 63 64 65 |
# File 'lib/sidekiq/web/config.rb', line 58 def initialize @options = OPTIONS.dup @locales = LOCALES @views = VIEWS @tabs = DEFAULT_TABS.dup @middlewares = [] @custom_job_info_rows = [] end |
Instance Attribute Details
#app_url ⇒ Object
Adds the “Back to App” link in the header
56 57 58 |
# File 'lib/sidekiq/web/config.rb', line 56 def app_url @app_url end |
#custom_job_info_rows ⇒ Object
Allows users to add custom rows to all of the Job tables, e.g. Retries, Dead, Scheduled, with custom links to other systems, see _job_info.erb and test in web_test.rb
Sidekiq::Web.configure do |cfg|
cfg.custom_job_info_rows << JobLogLink.new
end
class JobLogLink
def add_pair(job)
yield "External Logs", "<a href='https://example.com/logs/#{job.jid}'>Logs for #{job.jid}</a>"
end
end
48 49 50 |
# File 'lib/sidekiq/web/config.rb', line 48 def custom_job_info_rows @custom_job_info_rows end |
#locales ⇒ Object (readonly)
Returns the value of attribute locales.
51 52 53 |
# File 'lib/sidekiq/web/config.rb', line 51 def locales @locales end |
#middlewares ⇒ Object (readonly)
Returns the value of attribute middlewares.
53 54 55 |
# File 'lib/sidekiq/web/config.rb', line 53 def middlewares @middlewares end |
#tabs ⇒ Object (readonly)
Returns the value of attribute tabs.
50 51 52 |
# File 'lib/sidekiq/web/config.rb', line 50 def tabs @tabs end |
#views ⇒ Object (readonly)
Returns the value of attribute views.
52 53 54 |
# File 'lib/sidekiq/web/config.rb', line 52 def views @views end |
Instance Method Details
#register_extension(extclass, name:, tab:, index:, root_dir: nil, cache_for: 86400, asset_paths: nil) {|_self| ... } ⇒ Object Also known as: register
Register a class as a Sidekiq Web UI extension. The class should provide one or more tabs which map to an index route. Options:
Web extensions will have a root ‘web/` directory with `locales/`, `assets/` and `views/` subdirectories.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/sidekiq/web/config.rb', line 86 def register_extension(extclass, name:, tab:, index:, root_dir: nil, cache_for: 86400, asset_paths: nil) tab = Array(tab) index = Array(index) tab.zip(index).each do |tab, index| tabs[tab] = index end if root_dir locdir = File.join(root_dir, "locales") locales << locdir if File.directory?(locdir) if asset_paths && name # if you have {root}/assets/{name}/js/scripts.js # and {root}/assets/{name}/css/styles.css # you would pass in: # asset_paths: ["js", "css"] # See script_tag and style_tag in web/helpers.rb assdir = File.join(root_dir, "assets") assurls = Array(asset_paths).map { |x| "/#{name}/#{x}" } assetprops = { urls: assurls, root: assdir, cascade: true } assetprops[:header_rules] = [[:all, {"cache-control" => "private, max-age=#{cache_for.to_i}"}]] if cache_for middlewares << [[Rack::Static, assetprops], nil] end end yield self if block_given? extclass.registered(Web::Application) end |
#use(*args, &block) ⇒ Object
69 70 71 |
# File 'lib/sidekiq/web/config.rb', line 69 def use(*args, &block) middlewares << [args, block] end |