sidekiq 5.0.0 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sidekiq might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/.circleci/config.yml +61 -0
- data/.github/issue_template.md +3 -1
- data/.gitignore +1 -1
- data/.standard.yml +20 -0
- data/6.0-Upgrade.md +70 -0
- data/COMM-LICENSE +12 -10
- data/Changes.md +169 -1
- data/Ent-2.0-Upgrade.md +37 -0
- data/Ent-Changes.md +76 -0
- data/Gemfile +16 -21
- data/Gemfile.lock +196 -0
- data/LICENSE +1 -1
- data/Pro-4.0-Upgrade.md +35 -0
- data/Pro-5.0-Upgrade.md +25 -0
- data/Pro-Changes.md +137 -1
- data/README.md +18 -30
- data/Rakefile +6 -8
- data/bin/sidekiqload +28 -24
- data/bin/sidekiqmon +9 -0
- data/lib/generators/sidekiq/templates/worker_spec.rb.erb +1 -1
- data/lib/generators/sidekiq/templates/worker_test.rb.erb +1 -1
- data/lib/generators/sidekiq/worker_generator.rb +12 -14
- data/lib/sidekiq.rb +69 -49
- data/lib/sidekiq/api.rb +216 -160
- data/lib/sidekiq/cli.rb +174 -207
- data/lib/sidekiq/client.rb +55 -51
- data/lib/sidekiq/delay.rb +24 -4
- data/lib/sidekiq/exception_handler.rb +12 -16
- data/lib/sidekiq/extensions/action_mailer.rb +10 -20
- data/lib/sidekiq/extensions/active_record.rb +9 -7
- data/lib/sidekiq/extensions/class_methods.rb +9 -7
- data/lib/sidekiq/extensions/generic_proxy.rb +4 -4
- data/lib/sidekiq/fetch.rb +5 -6
- data/lib/sidekiq/job_logger.rb +42 -14
- data/lib/sidekiq/job_retry.rb +71 -57
- data/lib/sidekiq/launcher.rb +74 -60
- data/lib/sidekiq/logger.rb +69 -0
- data/lib/sidekiq/manager.rb +12 -15
- data/lib/sidekiq/middleware/chain.rb +3 -2
- data/lib/sidekiq/middleware/i18n.rb +5 -7
- data/lib/sidekiq/monitor.rb +148 -0
- data/lib/sidekiq/paginator.rb +11 -12
- data/lib/sidekiq/processor.rb +126 -82
- data/lib/sidekiq/rails.rb +24 -32
- data/lib/sidekiq/redis_connection.rb +46 -14
- data/lib/sidekiq/scheduled.rb +50 -25
- data/lib/sidekiq/testing.rb +35 -27
- data/lib/sidekiq/testing/inline.rb +2 -1
- data/lib/sidekiq/util.rb +20 -14
- data/lib/sidekiq/version.rb +2 -1
- data/lib/sidekiq/web.rb +45 -53
- data/lib/sidekiq/web/action.rb +14 -10
- data/lib/sidekiq/web/application.rb +83 -58
- data/lib/sidekiq/web/helpers.rb +105 -67
- data/lib/sidekiq/web/router.rb +18 -15
- data/lib/sidekiq/worker.rb +144 -41
- data/sidekiq.gemspec +16 -27
- data/web/assets/javascripts/application.js +0 -0
- data/web/assets/javascripts/dashboard.js +21 -23
- data/web/assets/stylesheets/application.css +35 -2
- data/web/assets/stylesheets/bootstrap.css +2 -2
- data/web/locales/ar.yml +1 -0
- data/web/locales/en.yml +2 -0
- data/web/locales/es.yml +4 -3
- data/web/locales/ja.yml +7 -4
- data/web/views/_footer.erb +4 -1
- data/web/views/_nav.erb +3 -17
- data/web/views/busy.erb +5 -1
- data/web/views/layout.erb +1 -1
- data/web/views/queue.erb +1 -0
- data/web/views/queues.erb +2 -0
- data/web/views/retries.erb +4 -0
- metadata +25 -171
- data/.travis.yml +0 -18
- data/bin/sidekiqctl +0 -99
- data/lib/sidekiq/core_ext.rb +0 -119
- data/lib/sidekiq/logging.rb +0 -106
- data/lib/sidekiq/middleware/server/active_record.rb +0 -22
data/lib/sidekiq/util.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
2
|
+
|
3
|
+
require "socket"
|
4
|
+
require "securerandom"
|
5
|
+
require "sidekiq/exception_handler"
|
6
6
|
|
7
7
|
module Sidekiq
|
8
8
|
##
|
@@ -16,13 +16,13 @@ module Sidekiq
|
|
16
16
|
def watchdog(last_words)
|
17
17
|
yield
|
18
18
|
rescue Exception => ex
|
19
|
-
handle_exception(ex, {
|
19
|
+
handle_exception(ex, {context: last_words})
|
20
20
|
raise ex
|
21
21
|
end
|
22
22
|
|
23
23
|
def safe_thread(name, &block)
|
24
24
|
Thread.new do
|
25
|
-
Thread.current
|
25
|
+
Thread.current.name = name
|
26
26
|
watchdog(name, &block)
|
27
27
|
end
|
28
28
|
end
|
@@ -35,8 +35,12 @@ module Sidekiq
|
|
35
35
|
Sidekiq.redis(&block)
|
36
36
|
end
|
37
37
|
|
38
|
+
def tid
|
39
|
+
Thread.current["sidekiq_tid"] ||= (Thread.current.object_id ^ ::Process.pid).to_s(36)
|
40
|
+
end
|
41
|
+
|
38
42
|
def hostname
|
39
|
-
ENV[
|
43
|
+
ENV["DYNO"] || Socket.gethostname
|
40
44
|
end
|
41
45
|
|
42
46
|
def process_nonce
|
@@ -44,18 +48,20 @@ module Sidekiq
|
|
44
48
|
end
|
45
49
|
|
46
50
|
def identity
|
47
|
-
@@identity ||= "#{hostname}:#{
|
51
|
+
@@identity ||= "#{hostname}:#{::Process.pid}:#{process_nonce}"
|
48
52
|
end
|
49
53
|
|
50
|
-
def fire_event(event,
|
54
|
+
def fire_event(event, options = {})
|
55
|
+
reverse = options[:reverse]
|
56
|
+
reraise = options[:reraise]
|
57
|
+
|
51
58
|
arr = Sidekiq.options[:lifecycle_events][event]
|
52
59
|
arr.reverse! if reverse
|
53
60
|
arr.each do |block|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
61
|
+
block.call
|
62
|
+
rescue => ex
|
63
|
+
handle_exception(ex, {context: "Exception during Sidekiq lifecycle event.", event: event})
|
64
|
+
raise ex if reraise
|
59
65
|
end
|
60
66
|
arr.clear
|
61
67
|
end
|
data/lib/sidekiq/version.rb
CHANGED
data/lib/sidekiq/web.rb
CHANGED
@@ -1,36 +1,37 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'erb'
|
3
2
|
|
4
|
-
require
|
5
|
-
require 'sidekiq/api'
|
6
|
-
require 'sidekiq/paginator'
|
7
|
-
require 'sidekiq/web/helpers'
|
3
|
+
require "erb"
|
8
4
|
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
5
|
+
require "sidekiq"
|
6
|
+
require "sidekiq/api"
|
7
|
+
require "sidekiq/paginator"
|
8
|
+
require "sidekiq/web/helpers"
|
12
9
|
|
13
|
-
require
|
10
|
+
require "sidekiq/web/router"
|
11
|
+
require "sidekiq/web/action"
|
12
|
+
require "sidekiq/web/application"
|
14
13
|
|
15
|
-
require
|
16
|
-
|
17
|
-
require
|
14
|
+
require "rack/protection"
|
15
|
+
|
16
|
+
require "rack/builder"
|
17
|
+
require "rack/file"
|
18
|
+
require "rack/session/cookie"
|
18
19
|
|
19
20
|
module Sidekiq
|
20
21
|
class Web
|
21
22
|
ROOT = File.expand_path("#{File.dirname(__FILE__)}/../../web")
|
22
|
-
VIEWS = "#{ROOT}/views"
|
23
|
-
LOCALES = ["#{ROOT}/locales"
|
24
|
-
LAYOUT = "#{VIEWS}/layout.erb"
|
25
|
-
ASSETS = "#{ROOT}/assets"
|
23
|
+
VIEWS = "#{ROOT}/views"
|
24
|
+
LOCALES = ["#{ROOT}/locales"]
|
25
|
+
LAYOUT = "#{VIEWS}/layout.erb"
|
26
|
+
ASSETS = "#{ROOT}/assets"
|
26
27
|
|
27
28
|
DEFAULT_TABS = {
|
28
|
-
"Dashboard" =>
|
29
|
-
"Busy"
|
30
|
-
"Queues"
|
31
|
-
"Retries"
|
32
|
-
"Scheduled" =>
|
33
|
-
"Dead"
|
29
|
+
"Dashboard" => "",
|
30
|
+
"Busy" => "busy",
|
31
|
+
"Queues" => "queues",
|
32
|
+
"Retries" => "retries",
|
33
|
+
"Scheduled" => "scheduled",
|
34
|
+
"Dead" => "morgue",
|
34
35
|
}
|
35
36
|
|
36
37
|
class << self
|
@@ -64,11 +65,11 @@ module Sidekiq
|
|
64
65
|
end
|
65
66
|
|
66
67
|
def enable(*opts)
|
67
|
-
opts.each {|key| set(key, true) }
|
68
|
+
opts.each { |key| set(key, true) }
|
68
69
|
end
|
69
70
|
|
70
71
|
def disable(*opts)
|
71
|
-
opts.each {|key| set(key, false) }
|
72
|
+
opts.each { |key| set(key, false) }
|
72
73
|
end
|
73
74
|
|
74
75
|
# Helper for the Sinatra syntax: Sidekiq::Web.set(:session_secret, Rails.application.secrets...)
|
@@ -81,10 +82,10 @@ module Sidekiq
|
|
81
82
|
end
|
82
83
|
|
83
84
|
def self.inherited(child)
|
84
|
-
child.app_url =
|
85
|
-
child.session_secret =
|
86
|
-
child.redis_pool =
|
87
|
-
child.sessions =
|
85
|
+
child.app_url = app_url
|
86
|
+
child.session_secret = session_secret
|
87
|
+
child.redis_pool = redis_pool
|
88
|
+
child.sessions = sessions
|
88
89
|
end
|
89
90
|
|
90
91
|
def settings
|
@@ -113,11 +114,11 @@ module Sidekiq
|
|
113
114
|
end
|
114
115
|
|
115
116
|
def enable(*opts)
|
116
|
-
opts.each {|key| set(key, true) }
|
117
|
+
opts.each { |key| set(key, true) }
|
117
118
|
end
|
118
119
|
|
119
120
|
def disable(*opts)
|
120
|
-
opts.each {|key| set(key, false) }
|
121
|
+
opts.each { |key| set(key, false) }
|
121
122
|
end
|
122
123
|
|
123
124
|
def set(attribute, value)
|
@@ -145,28 +146,28 @@ module Sidekiq
|
|
145
146
|
private
|
146
147
|
|
147
148
|
def using?(middleware)
|
148
|
-
middlewares.any? do |(m,_)|
|
149
|
-
m.
|
149
|
+
middlewares.any? do |(m, _)|
|
150
|
+
m.is_a?(Array) && (m[0] == middleware || m[0].is_a?(middleware))
|
150
151
|
end
|
151
152
|
end
|
152
153
|
|
153
154
|
def build_sessions
|
154
155
|
middlewares = self.middlewares
|
155
156
|
|
156
|
-
unless using?(::Rack::Protection) || ENV[
|
157
|
-
middlewares.unshift [[::Rack::Protection, {
|
157
|
+
unless using?(::Rack::Protection) || ENV["RACK_ENV"] == "test"
|
158
|
+
middlewares.unshift [[::Rack::Protection, {use: :authenticity_token}], nil]
|
158
159
|
end
|
159
160
|
|
160
161
|
s = sessions
|
161
162
|
return unless s
|
162
163
|
|
163
164
|
unless using? ::Rack::Session::Cookie
|
164
|
-
unless secret = Web.session_secret
|
165
|
-
require
|
165
|
+
unless (secret = Web.session_secret)
|
166
|
+
require "securerandom"
|
166
167
|
secret = SecureRandom.hex(64)
|
167
168
|
end
|
168
169
|
|
169
|
-
options = {
|
170
|
+
options = {secret: secret}
|
170
171
|
options = options.merge(s.to_hash) if s.respond_to? :to_hash
|
171
172
|
|
172
173
|
middlewares.unshift [[::Rack::Session::Cookie, options], nil]
|
@@ -180,13 +181,13 @@ module Sidekiq
|
|
180
181
|
klass = self.class
|
181
182
|
|
182
183
|
::Rack::Builder.new do
|
183
|
-
%w
|
184
|
+
%w[stylesheets javascripts images].each do |asset_dir|
|
184
185
|
map "/#{asset_dir}" do
|
185
|
-
run ::Rack::File.new("#{ASSETS}/#{asset_dir}", {
|
186
|
+
run ::Rack::File.new("#{ASSETS}/#{asset_dir}", {"Cache-Control" => "public, max-age=86400"})
|
186
187
|
end
|
187
188
|
end
|
188
189
|
|
189
|
-
middlewares.each {|middleware, block| use(*middleware, &block) }
|
190
|
+
middlewares.each { |middleware, block| use(*middleware, &block) }
|
190
191
|
|
191
192
|
run WebApplication.new(klass)
|
192
193
|
end
|
@@ -196,18 +197,9 @@ module Sidekiq
|
|
196
197
|
Sidekiq::WebApplication.helpers WebHelpers
|
197
198
|
Sidekiq::WebApplication.helpers Sidekiq::Paginator
|
198
199
|
|
199
|
-
Sidekiq::WebAction.class_eval
|
200
|
-
|
201
|
-
|
202
|
-
if defined?(::ActionDispatch::Request::Session) &&
|
203
|
-
!::ActionDispatch::Request::Session.method_defined?(:each)
|
204
|
-
# mperham/sidekiq#2460
|
205
|
-
# Rack apps can't reuse the Rails session store without
|
206
|
-
# this monkeypatch, fixed in Rails 5.
|
207
|
-
class ActionDispatch::Request::Session
|
208
|
-
def each(&block)
|
209
|
-
hash = self.to_hash
|
210
|
-
hash.each(&block)
|
200
|
+
Sidekiq::WebAction.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
201
|
+
def _render
|
202
|
+
#{ERB.new(File.read(Web::LAYOUT)).src}
|
211
203
|
end
|
212
|
-
|
204
|
+
RUBY
|
213
205
|
end
|
data/lib/sidekiq/web/action.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Sidekiq
|
4
4
|
class WebAction
|
5
|
-
RACK_SESSION =
|
5
|
+
RACK_SESSION = "rack.session"
|
6
6
|
|
7
7
|
attr_accessor :env, :block, :type
|
8
8
|
|
@@ -19,14 +19,14 @@ module Sidekiq
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def redirect(location)
|
22
|
-
throw :halt, [302, {
|
22
|
+
throw :halt, [302, {"Location" => "#{request.base_url}#{location}"}, []]
|
23
23
|
end
|
24
24
|
|
25
25
|
def params
|
26
|
-
indifferent_hash = Hash.new {|hash,key| hash[key.to_s] if Symbol === key }
|
26
|
+
indifferent_hash = Hash.new { |hash, key| hash[key.to_s] if Symbol === key }
|
27
27
|
|
28
28
|
indifferent_hash.merge! request.params
|
29
|
-
route_params.each {|k,v| indifferent_hash[k.to_s] = v }
|
29
|
+
route_params.each { |k, v| indifferent_hash[k.to_s] = v }
|
30
30
|
|
31
31
|
indifferent_hash
|
32
32
|
end
|
@@ -40,10 +40,14 @@ module Sidekiq
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def erb(content, options = {})
|
43
|
-
if content.
|
43
|
+
if content.is_a? Symbol
|
44
44
|
unless respond_to?(:"_erb_#{content}")
|
45
45
|
src = ERB.new(File.read("#{Web.settings.views}/#{content}.erb")).src
|
46
|
-
WebAction.class_eval
|
46
|
+
WebAction.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
47
|
+
def _erb_#{content}
|
48
|
+
#{src}
|
49
|
+
end
|
50
|
+
RUBY
|
47
51
|
end
|
48
52
|
end
|
49
53
|
|
@@ -64,22 +68,22 @@ module Sidekiq
|
|
64
68
|
end
|
65
69
|
|
66
70
|
def json(payload)
|
67
|
-
[200, {
|
71
|
+
[200, {"Content-Type" => "application/json", "Cache-Control" => "no-cache"}, [Sidekiq.dump_json(payload)]]
|
68
72
|
end
|
69
73
|
|
70
74
|
def initialize(env, block)
|
71
75
|
@_erb = false
|
72
76
|
@env = env
|
73
77
|
@block = block
|
74
|
-
|
78
|
+
@files ||= {}
|
75
79
|
end
|
76
80
|
|
77
81
|
private
|
78
82
|
|
79
83
|
def _erb(file, locals)
|
80
|
-
locals
|
84
|
+
locals&.each { |k, v| define_singleton_method(k) { v } unless singleton_methods.include? k }
|
81
85
|
|
82
|
-
if file.
|
86
|
+
if file.is_a?(String)
|
83
87
|
ERB.new(file).result(binding)
|
84
88
|
else
|
85
89
|
send(:"_erb_#{file}")
|
@@ -4,9 +4,24 @@ module Sidekiq
|
|
4
4
|
class WebApplication
|
5
5
|
extend WebRouter
|
6
6
|
|
7
|
-
CONTENT_LENGTH = "Content-Length"
|
8
|
-
CONTENT_TYPE = "Content-Type"
|
9
|
-
REDIS_KEYS = %w
|
7
|
+
CONTENT_LENGTH = "Content-Length"
|
8
|
+
CONTENT_TYPE = "Content-Type"
|
9
|
+
REDIS_KEYS = %w[redis_version uptime_in_days connected_clients used_memory_human used_memory_peak_human]
|
10
|
+
CSP_HEADER = [
|
11
|
+
"default-src 'self' https: http:",
|
12
|
+
"child-src 'self'",
|
13
|
+
"connect-src 'self' https: http: wss: ws:",
|
14
|
+
"font-src 'self' https: http:",
|
15
|
+
"frame-src 'self'",
|
16
|
+
"img-src 'self' https: http: data:",
|
17
|
+
"manifest-src 'self'",
|
18
|
+
"media-src 'self'",
|
19
|
+
"object-src 'none'",
|
20
|
+
"script-src 'self' https: http: 'unsafe-inline'",
|
21
|
+
"style-src 'self' https: http: 'unsafe-inline'",
|
22
|
+
"worker-src 'self'",
|
23
|
+
"base-uri 'self'",
|
24
|
+
].join("; ").freeze
|
10
25
|
|
11
26
|
def initialize(klass)
|
12
27
|
@klass = klass
|
@@ -29,8 +44,8 @@ module Sidekiq
|
|
29
44
|
end
|
30
45
|
|
31
46
|
get "/" do
|
32
|
-
@redis_info = redis_info.select{ |k, v| REDIS_KEYS.include? k }
|
33
|
-
stats_history = Sidekiq::Stats::History.new((params[
|
47
|
+
@redis_info = redis_info.select { |k, v| REDIS_KEYS.include? k }
|
48
|
+
stats_history = Sidekiq::Stats::History.new((params["days"] || 30).to_i)
|
34
49
|
@processed_history = stats_history.processed
|
35
50
|
@failed_history = stats_history.failed
|
36
51
|
|
@@ -42,14 +57,14 @@ module Sidekiq
|
|
42
57
|
end
|
43
58
|
|
44
59
|
post "/busy" do
|
45
|
-
if params[
|
46
|
-
p = Sidekiq::Process.new(
|
47
|
-
p.quiet! if params[
|
48
|
-
p.stop! if params[
|
60
|
+
if params["identity"]
|
61
|
+
p = Sidekiq::Process.new("identity" => params["identity"])
|
62
|
+
p.quiet! if params["quiet"]
|
63
|
+
p.stop! if params["stop"]
|
49
64
|
else
|
50
65
|
processes.each do |pro|
|
51
|
-
pro.quiet! if params[
|
52
|
-
pro.stop! if params[
|
66
|
+
pro.quiet! if params["quiet"]
|
67
|
+
pro.stop! if params["stop"]
|
53
68
|
end
|
54
69
|
end
|
55
70
|
|
@@ -67,9 +82,9 @@ module Sidekiq
|
|
67
82
|
|
68
83
|
halt(404) unless @name
|
69
84
|
|
70
|
-
@count = (params[
|
85
|
+
@count = (params["count"] || 25).to_i
|
71
86
|
@queue = Sidekiq::Queue.new(@name)
|
72
|
-
(@current_page, @total_size, @messages) = page("queue:#{@name}", params[
|
87
|
+
(@current_page, @total_size, @messages) = page("queue:#{@name}", params["page"], @count)
|
73
88
|
@messages = @messages.map { |msg| Sidekiq::Job.new(msg, @name) }
|
74
89
|
|
75
90
|
erb(:queue)
|
@@ -83,21 +98,22 @@ module Sidekiq
|
|
83
98
|
|
84
99
|
post "/queues/:name/delete" do
|
85
100
|
name = route_params[:name]
|
86
|
-
Sidekiq::Job.new(params[
|
101
|
+
Sidekiq::Job.new(params["key_val"], name).delete
|
87
102
|
|
88
103
|
redirect_with_query("#{root_path}queues/#{CGI.escape(name)}")
|
89
104
|
end
|
90
105
|
|
91
|
-
get
|
92
|
-
@count = (params[
|
93
|
-
(@current_page, @total_size, @dead) = page("dead", params[
|
106
|
+
get "/morgue" do
|
107
|
+
@count = (params["count"] || 25).to_i
|
108
|
+
(@current_page, @total_size, @dead) = page("dead", params["page"], @count, reverse: true)
|
94
109
|
@dead = @dead.map { |msg, score| Sidekiq::SortedEntry.new(nil, score, msg) }
|
95
110
|
|
96
111
|
erb(:morgue)
|
97
112
|
end
|
98
113
|
|
99
114
|
get "/morgue/:key" do
|
100
|
-
|
115
|
+
key = route_params[:key]
|
116
|
+
halt(404) unless key
|
101
117
|
|
102
118
|
@dead = Sidekiq::DeadSet.new.fetch(*parse_params(key)).first
|
103
119
|
|
@@ -108,10 +124,10 @@ module Sidekiq
|
|
108
124
|
end
|
109
125
|
end
|
110
126
|
|
111
|
-
post
|
112
|
-
redirect(request.path) unless params[
|
127
|
+
post "/morgue" do
|
128
|
+
redirect(request.path) unless params["key"]
|
113
129
|
|
114
|
-
params[
|
130
|
+
params["key"].each do |key|
|
115
131
|
job = Sidekiq::DeadSet.new.fetch(*parse_params(key)).first
|
116
132
|
retry_or_delete_or_kill job, params if job
|
117
133
|
end
|
@@ -132,7 +148,8 @@ module Sidekiq
|
|
132
148
|
end
|
133
149
|
|
134
150
|
post "/morgue/:key" do
|
135
|
-
|
151
|
+
key = route_params[:key]
|
152
|
+
halt(404) unless key
|
136
153
|
|
137
154
|
job = Sidekiq::DeadSet.new.fetch(*parse_params(key)).first
|
138
155
|
retry_or_delete_or_kill job, params if job
|
@@ -140,9 +157,9 @@ module Sidekiq
|
|
140
157
|
redirect_with_query("#{root_path}morgue")
|
141
158
|
end
|
142
159
|
|
143
|
-
get
|
144
|
-
@count = (params[
|
145
|
-
(@current_page, @total_size, @retries) = page("retry", params[
|
160
|
+
get "/retries" do
|
161
|
+
@count = (params["count"] || 25).to_i
|
162
|
+
(@current_page, @total_size, @retries) = page("retry", params["page"], @count)
|
146
163
|
@retries = @retries.map { |msg, score| Sidekiq::SortedEntry.new(nil, score, msg) }
|
147
164
|
|
148
165
|
erb(:retries)
|
@@ -158,10 +175,10 @@ module Sidekiq
|
|
158
175
|
end
|
159
176
|
end
|
160
177
|
|
161
|
-
post
|
162
|
-
redirect(request.path) unless params[
|
178
|
+
post "/retries" do
|
179
|
+
redirect(request.path) unless params["key"]
|
163
180
|
|
164
|
-
params[
|
181
|
+
params["key"].each do |key|
|
165
182
|
job = Sidekiq::RetrySet.new.fetch(*parse_params(key)).first
|
166
183
|
retry_or_delete_or_kill job, params if job
|
167
184
|
end
|
@@ -181,6 +198,12 @@ module Sidekiq
|
|
181
198
|
redirect "#{root_path}retries"
|
182
199
|
end
|
183
200
|
|
201
|
+
post "/retries/all/kill" do
|
202
|
+
Sidekiq::RetrySet.new.kill_all
|
203
|
+
|
204
|
+
redirect "#{root_path}retries"
|
205
|
+
end
|
206
|
+
|
184
207
|
post "/retries/:key" do
|
185
208
|
job = Sidekiq::RetrySet.new.fetch(*parse_params(route_params[:key])).first
|
186
209
|
|
@@ -189,9 +212,9 @@ module Sidekiq
|
|
189
212
|
redirect_with_query("#{root_path}retries")
|
190
213
|
end
|
191
214
|
|
192
|
-
get
|
193
|
-
@count = (params[
|
194
|
-
(@current_page, @total_size, @scheduled) = page("schedule", params[
|
215
|
+
get "/scheduled" do
|
216
|
+
@count = (params["count"] || 25).to_i
|
217
|
+
(@current_page, @total_size, @scheduled) = page("schedule", params["page"], @count)
|
195
218
|
@scheduled = @scheduled.map { |msg, score| Sidekiq::SortedEntry.new(nil, score, msg) }
|
196
219
|
|
197
220
|
erb(:scheduled)
|
@@ -207,10 +230,10 @@ module Sidekiq
|
|
207
230
|
end
|
208
231
|
end
|
209
232
|
|
210
|
-
post
|
211
|
-
redirect(request.path) unless params[
|
233
|
+
post "/scheduled" do
|
234
|
+
redirect(request.path) unless params["key"]
|
212
235
|
|
213
|
-
params[
|
236
|
+
params["key"].each do |key|
|
214
237
|
job = Sidekiq::ScheduledSet.new.fetch(*parse_params(key)).first
|
215
238
|
delete_or_add_queue job, params if job
|
216
239
|
end
|
@@ -219,7 +242,8 @@ module Sidekiq
|
|
219
242
|
end
|
220
243
|
|
221
244
|
post "/scheduled/:key" do
|
222
|
-
|
245
|
+
key = route_params[:key]
|
246
|
+
halt(404) unless key
|
223
247
|
|
224
248
|
job = Sidekiq::ScheduledSet.new.fetch(*parse_params(key)).first
|
225
249
|
delete_or_add_queue job, params if job
|
@@ -227,39 +251,39 @@ module Sidekiq
|
|
227
251
|
redirect_with_query("#{root_path}scheduled")
|
228
252
|
end
|
229
253
|
|
230
|
-
get
|
254
|
+
get "/dashboard/stats" do
|
231
255
|
redirect "#{root_path}stats"
|
232
256
|
end
|
233
257
|
|
234
|
-
get
|
258
|
+
get "/stats" do
|
235
259
|
sidekiq_stats = Sidekiq::Stats.new
|
236
|
-
redis_stats
|
237
|
-
|
260
|
+
redis_stats = redis_info.select { |k, v| REDIS_KEYS.include? k }
|
238
261
|
json(
|
239
262
|
sidekiq: {
|
240
|
-
processed:
|
241
|
-
failed:
|
242
|
-
busy:
|
243
|
-
processes:
|
244
|
-
enqueued:
|
245
|
-
scheduled:
|
246
|
-
retries:
|
247
|
-
dead:
|
248
|
-
default_latency: sidekiq_stats.default_queue_latency
|
263
|
+
processed: sidekiq_stats.processed,
|
264
|
+
failed: sidekiq_stats.failed,
|
265
|
+
busy: sidekiq_stats.workers_size,
|
266
|
+
processes: sidekiq_stats.processes_size,
|
267
|
+
enqueued: sidekiq_stats.enqueued,
|
268
|
+
scheduled: sidekiq_stats.scheduled_size,
|
269
|
+
retries: sidekiq_stats.retry_size,
|
270
|
+
dead: sidekiq_stats.dead_size,
|
271
|
+
default_latency: sidekiq_stats.default_queue_latency,
|
249
272
|
},
|
250
|
-
redis: redis_stats
|
273
|
+
redis: redis_stats,
|
274
|
+
server_utc_time: server_utc_time
|
251
275
|
)
|
252
276
|
end
|
253
277
|
|
254
|
-
get
|
278
|
+
get "/stats/queues" do
|
255
279
|
json Sidekiq::Stats::Queues.new.lengths
|
256
280
|
end
|
257
281
|
|
258
282
|
def call(env)
|
259
283
|
action = self.class.match(env)
|
260
|
-
return [404, {"Content-Type" => "text/plain", "X-Cascade" => "pass"
|
284
|
+
return [404, {"Content-Type" => "text/plain", "X-Cascade" => "pass"}, ["Not Found"]] unless action
|
261
285
|
|
262
|
-
resp = catch(:halt)
|
286
|
+
resp = catch(:halt) {
|
263
287
|
app = @klass
|
264
288
|
self.class.run_befores(app, action)
|
265
289
|
begin
|
@@ -269,7 +293,7 @@ module Sidekiq
|
|
269
293
|
end
|
270
294
|
|
271
295
|
resp
|
272
|
-
|
296
|
+
}
|
273
297
|
|
274
298
|
resp = case resp
|
275
299
|
when Array
|
@@ -279,6 +303,7 @@ module Sidekiq
|
|
279
303
|
"Content-Type" => "text/html",
|
280
304
|
"Cache-Control" => "no-cache",
|
281
305
|
"Content-Language" => action.locale,
|
306
|
+
"Content-Security-Policy" => CSP_HEADER,
|
282
307
|
}
|
283
308
|
|
284
309
|
[200, headers, [resp]]
|
@@ -291,7 +316,7 @@ module Sidekiq
|
|
291
316
|
resp
|
292
317
|
end
|
293
318
|
|
294
|
-
def self.helpers(mod=nil, &block)
|
319
|
+
def self.helpers(mod = nil, &block)
|
295
320
|
if block_given?
|
296
321
|
WebAction.class_eval(&block)
|
297
322
|
else
|
@@ -299,11 +324,11 @@ module Sidekiq
|
|
299
324
|
end
|
300
325
|
end
|
301
326
|
|
302
|
-
def self.before(path=nil, &block)
|
327
|
+
def self.before(path = nil, &block)
|
303
328
|
befores << [path && Regexp.new("\\A#{path.gsub("*", ".*")}\\z"), block]
|
304
329
|
end
|
305
330
|
|
306
|
-
def self.after(path=nil, &block)
|
331
|
+
def self.after(path = nil, &block)
|
307
332
|
afters << [path && Regexp.new("\\A#{path.gsub("*", ".*")}\\z"), block]
|
308
333
|
end
|
309
334
|
|
@@ -316,8 +341,8 @@ module Sidekiq
|
|
316
341
|
end
|
317
342
|
|
318
343
|
def self.run_hooks(hooks, app, action)
|
319
|
-
hooks.select { |p,_| !p || p =~ action.env[WebRouter::PATH_INFO] }
|
320
|
-
|
344
|
+
hooks.select { |p, _| !p || p =~ action.env[WebRouter::PATH_INFO] }
|
345
|
+
.each { |_, b| action.instance_exec(action.env, app, &b) }
|
321
346
|
end
|
322
347
|
|
323
348
|
def self.befores
|