-
Notifications
You must be signed in to change notification settings - Fork 78
/
web.rb
43 lines (34 loc) · 946 Bytes
/
web.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# frozen_string_literal: true
# stdlib
require "pathname"
# 3rd party
require "sidekiq"
require "sidekiq/web"
# internal
require_relative "./registry"
require_relative "./web/stats"
module Sidekiq
module Throttled
# Provides Sidekiq tab to monitor and reset throttled stats.
module Web
VIEWS = Pathname.new(__dir__).join("web")
THROTTLED_TPL = VIEWS.join("throttled.html.erb").read.freeze
class << self
# @api private
def registered(app)
register_throttled_tab app
end
private
def register_throttled_tab(app)
app.get("/throttled") { erb THROTTLED_TPL.dup }
app.post("/throttled/:id/reset") do
Registry.get(params[:id], &:reset!)
redirect "#{root_path}throttled"
end
end
end
end
end
end
Sidekiq::Web.register Sidekiq::Throttled::Web
Sidekiq::Web.tabs["Throttled"] = "throttled"