sidekiq 5.2.9 → 6.4.1
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 +4 -4
- data/Changes.md +318 -1
- data/LICENSE +3 -3
- data/README.md +23 -34
- data/bin/sidekiq +27 -3
- data/bin/sidekiqload +67 -61
- data/bin/sidekiqmon +8 -0
- data/lib/generators/sidekiq/job_generator.rb +57 -0
- data/lib/generators/sidekiq/templates/{worker.rb.erb → job.rb.erb} +2 -2
- data/lib/generators/sidekiq/templates/{worker_spec.rb.erb → job_spec.rb.erb} +1 -1
- data/lib/generators/sidekiq/templates/{worker_test.rb.erb → job_test.rb.erb} +1 -1
- data/lib/sidekiq/api.rb +335 -267
- data/lib/sidekiq/cli.rb +164 -182
- data/lib/sidekiq/client.rb +58 -61
- data/lib/sidekiq/delay.rb +7 -6
- data/lib/sidekiq/exception_handler.rb +10 -12
- data/lib/sidekiq/extensions/action_mailer.rb +13 -22
- data/lib/sidekiq/extensions/active_record.rb +13 -10
- data/lib/sidekiq/extensions/class_methods.rb +14 -11
- data/lib/sidekiq/extensions/generic_proxy.rb +6 -4
- data/lib/sidekiq/fetch.rb +40 -32
- data/lib/sidekiq/job.rb +13 -0
- data/lib/sidekiq/job_logger.rb +33 -7
- data/lib/sidekiq/job_retry.rb +70 -71
- data/lib/sidekiq/job_util.rb +65 -0
- data/lib/sidekiq/launcher.rb +161 -71
- data/lib/sidekiq/logger.rb +170 -0
- data/lib/sidekiq/manager.rb +17 -21
- data/lib/sidekiq/middleware/chain.rb +20 -8
- data/lib/sidekiq/middleware/current_attributes.rb +57 -0
- data/lib/sidekiq/middleware/i18n.rb +5 -7
- data/lib/sidekiq/monitor.rb +133 -0
- data/lib/sidekiq/paginator.rb +20 -16
- data/lib/sidekiq/processor.rb +71 -70
- data/lib/sidekiq/rails.rb +40 -37
- data/lib/sidekiq/redis_connection.rb +48 -48
- data/lib/sidekiq/scheduled.rb +62 -28
- data/lib/sidekiq/sd_notify.rb +149 -0
- data/lib/sidekiq/systemd.rb +24 -0
- data/lib/sidekiq/testing/inline.rb +2 -1
- data/lib/sidekiq/testing.rb +36 -27
- data/lib/sidekiq/util.rb +57 -15
- data/lib/sidekiq/version.rb +2 -1
- data/lib/sidekiq/web/action.rb +15 -11
- data/lib/sidekiq/web/application.rb +88 -75
- data/lib/sidekiq/web/csrf_protection.rb +180 -0
- data/lib/sidekiq/web/helpers.rb +109 -92
- data/lib/sidekiq/web/router.rb +23 -19
- data/lib/sidekiq/web.rb +61 -105
- data/lib/sidekiq/worker.rb +247 -105
- data/lib/sidekiq.rb +77 -44
- data/sidekiq.gemspec +23 -16
- data/web/assets/images/apple-touch-icon.png +0 -0
- data/web/assets/javascripts/application.js +83 -64
- data/web/assets/javascripts/dashboard.js +54 -73
- data/web/assets/stylesheets/application-dark.css +143 -0
- data/web/assets/stylesheets/application-rtl.css +0 -4
- data/web/assets/stylesheets/application.css +45 -232
- data/web/locales/ar.yml +8 -2
- data/web/locales/de.yml +14 -2
- data/web/locales/en.yml +6 -1
- data/web/locales/es.yml +18 -2
- data/web/locales/fr.yml +10 -3
- data/web/locales/ja.yml +7 -1
- data/web/locales/lt.yml +83 -0
- data/web/locales/pl.yml +4 -4
- data/web/locales/ru.yml +4 -0
- data/web/locales/vi.yml +83 -0
- data/web/views/_footer.erb +1 -1
- data/web/views/_job_info.erb +3 -2
- data/web/views/_poll_link.erb +2 -5
- data/web/views/_summary.erb +7 -7
- data/web/views/busy.erb +54 -20
- data/web/views/dashboard.erb +22 -14
- data/web/views/dead.erb +3 -3
- data/web/views/layout.erb +3 -1
- data/web/views/morgue.erb +9 -6
- data/web/views/queue.erb +19 -10
- data/web/views/queues.erb +10 -2
- data/web/views/retries.erb +11 -8
- data/web/views/retry.erb +3 -3
- data/web/views/scheduled.erb +5 -2
- metadata +34 -64
- data/.circleci/config.yml +0 -61
- data/.github/contributing.md +0 -32
- data/.github/issue_template.md +0 -11
- data/.gitignore +0 -15
- data/.travis.yml +0 -11
- data/3.0-Upgrade.md +0 -70
- data/4.0-Upgrade.md +0 -53
- data/5.0-Upgrade.md +0 -56
- data/COMM-LICENSE +0 -97
- data/Ent-Changes.md +0 -238
- data/Gemfile +0 -23
- data/Pro-2.0-Upgrade.md +0 -138
- data/Pro-3.0-Upgrade.md +0 -44
- data/Pro-4.0-Upgrade.md +0 -35
- data/Pro-Changes.md +0 -759
- data/Rakefile +0 -9
- data/bin/sidekiqctl +0 -20
- data/code_of_conduct.md +0 -50
- data/lib/generators/sidekiq/worker_generator.rb +0 -49
- data/lib/sidekiq/core_ext.rb +0 -1
- data/lib/sidekiq/ctl.rb +0 -221
- data/lib/sidekiq/logging.rb +0 -122
- data/lib/sidekiq/middleware/server/active_record.rb +0 -23
@@ -0,0 +1,170 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "logger"
|
4
|
+
require "time"
|
5
|
+
|
6
|
+
module Sidekiq
|
7
|
+
module Context
|
8
|
+
def self.with(hash)
|
9
|
+
orig_context = current.dup
|
10
|
+
current.merge!(hash)
|
11
|
+
yield
|
12
|
+
ensure
|
13
|
+
Thread.current[:sidekiq_context] = orig_context
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.current
|
17
|
+
Thread.current[:sidekiq_context] ||= {}
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.add(k, v)
|
21
|
+
Thread.current[:sidekiq_context][k] = v
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module LoggingUtils
|
26
|
+
LEVELS = {
|
27
|
+
"debug" => 0,
|
28
|
+
"info" => 1,
|
29
|
+
"warn" => 2,
|
30
|
+
"error" => 3,
|
31
|
+
"fatal" => 4
|
32
|
+
}
|
33
|
+
LEVELS.default_proc = proc do |_, level|
|
34
|
+
Sidekiq.logger.warn("Invalid log level: #{level.inspect}")
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
|
38
|
+
def debug?
|
39
|
+
level <= 0
|
40
|
+
end
|
41
|
+
|
42
|
+
def info?
|
43
|
+
level <= 1
|
44
|
+
end
|
45
|
+
|
46
|
+
def warn?
|
47
|
+
level <= 2
|
48
|
+
end
|
49
|
+
|
50
|
+
def error?
|
51
|
+
level <= 3
|
52
|
+
end
|
53
|
+
|
54
|
+
def fatal?
|
55
|
+
level <= 4
|
56
|
+
end
|
57
|
+
|
58
|
+
def local_level
|
59
|
+
Thread.current[:sidekiq_log_level]
|
60
|
+
end
|
61
|
+
|
62
|
+
def local_level=(level)
|
63
|
+
case level
|
64
|
+
when Integer
|
65
|
+
Thread.current[:sidekiq_log_level] = level
|
66
|
+
when Symbol, String
|
67
|
+
Thread.current[:sidekiq_log_level] = LEVELS[level.to_s]
|
68
|
+
when nil
|
69
|
+
Thread.current[:sidekiq_log_level] = nil
|
70
|
+
else
|
71
|
+
raise ArgumentError, "Invalid log level: #{level.inspect}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def level
|
76
|
+
local_level || super
|
77
|
+
end
|
78
|
+
|
79
|
+
# Change the thread-local level for the duration of the given block.
|
80
|
+
def log_at(level)
|
81
|
+
old_local_level = local_level
|
82
|
+
self.local_level = level
|
83
|
+
yield
|
84
|
+
ensure
|
85
|
+
self.local_level = old_local_level
|
86
|
+
end
|
87
|
+
|
88
|
+
# Redefined to check severity against #level, and thus the thread-local level, rather than +@level+.
|
89
|
+
# FIXME: Remove when the minimum Ruby version supports overriding Logger#level.
|
90
|
+
def add(severity, message = nil, progname = nil, &block)
|
91
|
+
severity ||= ::Logger::UNKNOWN
|
92
|
+
progname ||= @progname
|
93
|
+
|
94
|
+
return true if @logdev.nil? || severity < level
|
95
|
+
|
96
|
+
if message.nil?
|
97
|
+
if block
|
98
|
+
message = yield
|
99
|
+
else
|
100
|
+
message = progname
|
101
|
+
progname = @progname
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
@logdev.write format_message(format_severity(severity), Time.now, progname, message)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
class Logger < ::Logger
|
110
|
+
include LoggingUtils
|
111
|
+
|
112
|
+
def initialize(*args, **kwargs)
|
113
|
+
super
|
114
|
+
self.formatter = Sidekiq.log_formatter
|
115
|
+
end
|
116
|
+
|
117
|
+
module Formatters
|
118
|
+
class Base < ::Logger::Formatter
|
119
|
+
def tid
|
120
|
+
Thread.current["sidekiq_tid"] ||= (Thread.current.object_id ^ ::Process.pid).to_s(36)
|
121
|
+
end
|
122
|
+
|
123
|
+
def ctx
|
124
|
+
Sidekiq::Context.current
|
125
|
+
end
|
126
|
+
|
127
|
+
def format_context
|
128
|
+
if ctx.any?
|
129
|
+
" " + ctx.compact.map { |k, v|
|
130
|
+
case v
|
131
|
+
when Array
|
132
|
+
"#{k}=#{v.join(",")}"
|
133
|
+
else
|
134
|
+
"#{k}=#{v}"
|
135
|
+
end
|
136
|
+
}.join(" ")
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
class Pretty < Base
|
142
|
+
def call(severity, time, program_name, message)
|
143
|
+
"#{time.utc.iso8601(3)} pid=#{::Process.pid} tid=#{tid}#{format_context} #{severity}: #{message}\n"
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
class WithoutTimestamp < Pretty
|
148
|
+
def call(severity, time, program_name, message)
|
149
|
+
"pid=#{::Process.pid} tid=#{tid}#{format_context} #{severity}: #{message}\n"
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
class JSON < Base
|
154
|
+
def call(severity, time, program_name, message)
|
155
|
+
hash = {
|
156
|
+
ts: time.utc.iso8601(3),
|
157
|
+
pid: ::Process.pid,
|
158
|
+
tid: tid,
|
159
|
+
lvl: severity,
|
160
|
+
msg: message
|
161
|
+
}
|
162
|
+
c = ctx
|
163
|
+
hash["ctx"] = c unless c.empty?
|
164
|
+
|
165
|
+
Sidekiq.dump_json(hash) << "\n"
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
data/lib/sidekiq/manager.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'sidekiq/util'
|
3
|
-
require 'sidekiq/processor'
|
4
|
-
require 'sidekiq/fetch'
|
5
|
-
require 'thread'
|
6
|
-
require 'set'
|
7
2
|
|
8
|
-
|
3
|
+
require "sidekiq/util"
|
4
|
+
require "sidekiq/processor"
|
5
|
+
require "sidekiq/fetch"
|
6
|
+
require "set"
|
9
7
|
|
8
|
+
module Sidekiq
|
10
9
|
##
|
11
10
|
# The Manager is the central coordination point in Sidekiq, controlling
|
12
11
|
# the lifecycle of the Processors.
|
@@ -27,7 +26,7 @@ module Sidekiq
|
|
27
26
|
attr_reader :workers
|
28
27
|
attr_reader :options
|
29
28
|
|
30
|
-
def initialize(options={})
|
29
|
+
def initialize(options = {})
|
31
30
|
logger.debug { options.inspect }
|
32
31
|
@options = options
|
33
32
|
@count = options[:concurrency] || 10
|
@@ -36,7 +35,7 @@ module Sidekiq
|
|
36
35
|
@done = false
|
37
36
|
@workers = Set.new
|
38
37
|
@count.times do
|
39
|
-
@workers << Processor.new(self)
|
38
|
+
@workers << Processor.new(self, options)
|
40
39
|
end
|
41
40
|
@plock = Mutex.new
|
42
41
|
end
|
@@ -56,9 +55,6 @@ module Sidekiq
|
|
56
55
|
fire_event(:quiet, reverse: true)
|
57
56
|
end
|
58
57
|
|
59
|
-
# hack for quicker development / testing environment #2774
|
60
|
-
PAUSE_TIME = STDOUT.tty? ? 0.1 : 0.5
|
61
|
-
|
62
58
|
def stop(deadline)
|
63
59
|
quiet
|
64
60
|
fire_event(:shutdown, reverse: true)
|
@@ -70,12 +66,7 @@ module Sidekiq
|
|
70
66
|
return if @workers.empty?
|
71
67
|
|
72
68
|
logger.info { "Pausing to allow workers to finish..." }
|
73
|
-
|
74
|
-
while remaining > PAUSE_TIME
|
75
|
-
return if @workers.empty?
|
76
|
-
sleep PAUSE_TIME
|
77
|
-
remaining = deadline - ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
|
78
|
-
end
|
69
|
+
wait_for(deadline) { @workers.empty? }
|
79
70
|
return if @workers.empty?
|
80
71
|
|
81
72
|
hard_shutdown
|
@@ -91,7 +82,7 @@ module Sidekiq
|
|
91
82
|
@plock.synchronize do
|
92
83
|
@workers.delete(processor)
|
93
84
|
unless @done
|
94
|
-
p = Processor.new(self)
|
85
|
+
p = Processor.new(self, options)
|
95
86
|
@workers << p
|
96
87
|
p.start
|
97
88
|
end
|
@@ -113,7 +104,7 @@ module Sidekiq
|
|
113
104
|
end
|
114
105
|
|
115
106
|
if cleanup.size > 0
|
116
|
-
jobs = cleanup.map {|p| p.job }.compact
|
107
|
+
jobs = cleanup.map { |p| p.job }.compact
|
117
108
|
|
118
109
|
logger.warn { "Terminating #{cleanup.size} busy worker threads" }
|
119
110
|
logger.warn { "Work still in progress #{jobs.inspect}" }
|
@@ -124,14 +115,19 @@ module Sidekiq
|
|
124
115
|
# contract says that jobs are run AT LEAST once. Process termination
|
125
116
|
# is delayed until we're certain the jobs are back in Redis because
|
126
117
|
# it is worse to lose a job than to run it twice.
|
127
|
-
strategy =
|
118
|
+
strategy = @options[:fetch]
|
128
119
|
strategy.bulk_requeue(jobs, @options)
|
129
120
|
end
|
130
121
|
|
131
122
|
cleanup.each do |processor|
|
132
123
|
processor.kill
|
133
124
|
end
|
134
|
-
end
|
135
125
|
|
126
|
+
# when this method returns, we immediately call `exit` which may not give
|
127
|
+
# the remaining threads time to run `ensure` blocks, etc. We pause here up
|
128
|
+
# to 3 seconds to give threads a minimal amount of time to run `ensure` blocks.
|
129
|
+
deadline = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) + 3
|
130
|
+
wait_for(deadline) { @workers.empty? }
|
131
|
+
end
|
136
132
|
end
|
137
133
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Sidekiq
|
3
4
|
# Middleware is code configured to run before/after
|
4
5
|
# a message is processed. It is patterned after Rack
|
@@ -66,7 +67,6 @@ module Sidekiq
|
|
66
67
|
module Middleware
|
67
68
|
class Chain
|
68
69
|
include Enumerable
|
69
|
-
attr_reader :entries
|
70
70
|
|
71
71
|
def initialize_copy(copy)
|
72
72
|
copy.instance_variable_set(:@entries, entries.dup)
|
@@ -77,21 +77,25 @@ module Sidekiq
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def initialize
|
80
|
-
@entries =
|
80
|
+
@entries = nil
|
81
81
|
yield self if block_given?
|
82
82
|
end
|
83
83
|
|
84
|
+
def entries
|
85
|
+
@entries ||= []
|
86
|
+
end
|
87
|
+
|
84
88
|
def remove(klass)
|
85
89
|
entries.delete_if { |entry| entry.klass == klass }
|
86
90
|
end
|
87
91
|
|
88
92
|
def add(klass, *args)
|
89
|
-
remove(klass)
|
93
|
+
remove(klass)
|
90
94
|
entries << Entry.new(klass, *args)
|
91
95
|
end
|
92
96
|
|
93
97
|
def prepend(klass, *args)
|
94
|
-
remove(klass)
|
98
|
+
remove(klass)
|
95
99
|
entries.insert(0, Entry.new(klass, *args))
|
96
100
|
end
|
97
101
|
|
@@ -106,13 +110,17 @@ module Sidekiq
|
|
106
110
|
i = entries.index { |entry| entry.klass == newklass }
|
107
111
|
new_entry = i.nil? ? Entry.new(newklass, *args) : entries.delete_at(i)
|
108
112
|
i = entries.index { |entry| entry.klass == oldklass } || entries.count - 1
|
109
|
-
entries.insert(i+1, new_entry)
|
113
|
+
entries.insert(i + 1, new_entry)
|
110
114
|
end
|
111
115
|
|
112
116
|
def exists?(klass)
|
113
117
|
any? { |entry| entry.klass == klass }
|
114
118
|
end
|
115
119
|
|
120
|
+
def empty?
|
121
|
+
@entries.nil? || @entries.empty?
|
122
|
+
end
|
123
|
+
|
116
124
|
def retrieve
|
117
125
|
map(&:make_new)
|
118
126
|
end
|
@@ -122,8 +130,10 @@ module Sidekiq
|
|
122
130
|
end
|
123
131
|
|
124
132
|
def invoke(*args)
|
125
|
-
|
126
|
-
|
133
|
+
return yield if empty?
|
134
|
+
|
135
|
+
chain = retrieve
|
136
|
+
traverse_chain = proc do
|
127
137
|
if chain.empty?
|
128
138
|
yield
|
129
139
|
else
|
@@ -134,12 +144,14 @@ module Sidekiq
|
|
134
144
|
end
|
135
145
|
end
|
136
146
|
|
147
|
+
private
|
148
|
+
|
137
149
|
class Entry
|
138
150
|
attr_reader :klass
|
139
151
|
|
140
152
|
def initialize(klass, *args)
|
141
153
|
@klass = klass
|
142
|
-
@args
|
154
|
+
@args = args
|
143
155
|
end
|
144
156
|
|
145
157
|
def make_new
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "active_support/current_attributes"
|
2
|
+
|
3
|
+
module Sidekiq
|
4
|
+
##
|
5
|
+
# Automatically save and load any current attributes in the execution context
|
6
|
+
# so context attributes "flow" from Rails actions into any associated jobs.
|
7
|
+
# This can be useful for multi-tenancy, i18n locale, timezone, any implicit
|
8
|
+
# per-request attribute. See +ActiveSupport::CurrentAttributes+.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
#
|
12
|
+
# # in your initializer
|
13
|
+
# require "sidekiq/middleware/current_attributes"
|
14
|
+
# Sidekiq::CurrentAttributes.persist(Myapp::Current)
|
15
|
+
#
|
16
|
+
module CurrentAttributes
|
17
|
+
class Save
|
18
|
+
def initialize(cattr)
|
19
|
+
@klass = cattr
|
20
|
+
end
|
21
|
+
|
22
|
+
def call(_, job, _, _)
|
23
|
+
attrs = @klass.attributes
|
24
|
+
if job.has_key?("cattr")
|
25
|
+
job["cattr"].merge!(attrs)
|
26
|
+
else
|
27
|
+
job["cattr"] = attrs
|
28
|
+
end
|
29
|
+
yield
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Load
|
34
|
+
def initialize(cattr)
|
35
|
+
@klass = cattr
|
36
|
+
end
|
37
|
+
|
38
|
+
def call(_, job, _, &block)
|
39
|
+
if job.has_key?("cattr")
|
40
|
+
@klass.set(job["cattr"], &block)
|
41
|
+
else
|
42
|
+
yield
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.persist(klass)
|
48
|
+
Sidekiq.configure_client do |config|
|
49
|
+
config.client_middleware.add Save, klass
|
50
|
+
end
|
51
|
+
Sidekiq.configure_server do |config|
|
52
|
+
config.client_middleware.add Save, klass
|
53
|
+
config.server_middleware.add Load, klass
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
#
|
3
4
|
# Simple middleware to save the current locale and restore it when the job executes.
|
4
5
|
# Use it by requiring it in your initializer:
|
@@ -9,19 +10,16 @@ module Sidekiq::Middleware::I18n
|
|
9
10
|
# Get the current locale and store it in the message
|
10
11
|
# to be sent to Sidekiq.
|
11
12
|
class Client
|
12
|
-
def call(
|
13
|
-
msg[
|
13
|
+
def call(_worker, msg, _queue, _redis)
|
14
|
+
msg["locale"] ||= I18n.locale
|
14
15
|
yield
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
18
19
|
# Pull the msg locale out and set the current thread to use it.
|
19
20
|
class Server
|
20
|
-
def call(
|
21
|
-
I18n.
|
22
|
-
yield
|
23
|
-
ensure
|
24
|
-
I18n.locale = I18n.default_locale
|
21
|
+
def call(_worker, msg, _queue, &block)
|
22
|
+
I18n.with_locale(msg.fetch("locale", I18n.default_locale), &block)
|
25
23
|
end
|
26
24
|
end
|
27
25
|
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "fileutils"
|
4
|
+
require "sidekiq/api"
|
5
|
+
|
6
|
+
class Sidekiq::Monitor
|
7
|
+
class Status
|
8
|
+
VALID_SECTIONS = %w[all version overview processes queues]
|
9
|
+
COL_PAD = 2
|
10
|
+
|
11
|
+
def display(section = nil)
|
12
|
+
section ||= "all"
|
13
|
+
unless VALID_SECTIONS.include? section
|
14
|
+
puts "I don't know how to check the status of '#{section}'!"
|
15
|
+
puts "Try one of these: #{VALID_SECTIONS.join(", ")}"
|
16
|
+
return
|
17
|
+
end
|
18
|
+
send(section)
|
19
|
+
rescue => e
|
20
|
+
puts "Couldn't get status: #{e}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def all
|
24
|
+
version
|
25
|
+
puts
|
26
|
+
overview
|
27
|
+
puts
|
28
|
+
processes
|
29
|
+
puts
|
30
|
+
queues
|
31
|
+
end
|
32
|
+
|
33
|
+
def version
|
34
|
+
puts "Sidekiq #{Sidekiq::VERSION}"
|
35
|
+
puts Time.now.utc
|
36
|
+
end
|
37
|
+
|
38
|
+
def overview
|
39
|
+
puts "---- Overview ----"
|
40
|
+
puts " Processed: #{delimit stats.processed}"
|
41
|
+
puts " Failed: #{delimit stats.failed}"
|
42
|
+
puts " Busy: #{delimit stats.workers_size}"
|
43
|
+
puts " Enqueued: #{delimit stats.enqueued}"
|
44
|
+
puts " Retries: #{delimit stats.retry_size}"
|
45
|
+
puts " Scheduled: #{delimit stats.scheduled_size}"
|
46
|
+
puts " Dead: #{delimit stats.dead_size}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def processes
|
50
|
+
puts "---- Processes (#{process_set.size}) ----"
|
51
|
+
process_set.each_with_index do |process, index|
|
52
|
+
puts "#{process["identity"]} #{tags_for(process)}"
|
53
|
+
puts " Started: #{Time.at(process["started_at"])} (#{time_ago(process["started_at"])})"
|
54
|
+
puts " Threads: #{process["concurrency"]} (#{process["busy"]} busy)"
|
55
|
+
puts " Queues: #{split_multiline(process["queues"].sort, pad: 11)}"
|
56
|
+
puts "" unless (index + 1) == process_set.size
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def queues
|
61
|
+
puts "---- Queues (#{queue_data.size}) ----"
|
62
|
+
columns = {
|
63
|
+
name: [:ljust, (["name"] + queue_data.map(&:name)).map(&:length).max + COL_PAD],
|
64
|
+
size: [:rjust, (["size"] + queue_data.map(&:size)).map(&:length).max + COL_PAD],
|
65
|
+
latency: [:rjust, (["latency"] + queue_data.map(&:latency)).map(&:length).max + COL_PAD]
|
66
|
+
}
|
67
|
+
columns.each { |col, (dir, width)| print col.to_s.upcase.public_send(dir, width) }
|
68
|
+
puts
|
69
|
+
queue_data.each do |q|
|
70
|
+
columns.each do |col, (dir, width)|
|
71
|
+
print q.send(col).public_send(dir, width)
|
72
|
+
end
|
73
|
+
puts
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def delimit(number)
|
80
|
+
number.to_s.reverse.scan(/.{1,3}/).join(",").reverse
|
81
|
+
end
|
82
|
+
|
83
|
+
def split_multiline(values, opts = {})
|
84
|
+
return "none" unless values
|
85
|
+
pad = opts[:pad] || 0
|
86
|
+
max_length = opts[:max_length] || (80 - pad)
|
87
|
+
out = []
|
88
|
+
line = ""
|
89
|
+
values.each do |value|
|
90
|
+
if (line.length + value.length) > max_length
|
91
|
+
out << line
|
92
|
+
line = " " * pad
|
93
|
+
end
|
94
|
+
line << value + ", "
|
95
|
+
end
|
96
|
+
out << line[0..-3]
|
97
|
+
out.join("\n")
|
98
|
+
end
|
99
|
+
|
100
|
+
def tags_for(process)
|
101
|
+
tags = [
|
102
|
+
process["tag"],
|
103
|
+
process["labels"],
|
104
|
+
(process["quiet"] == "true" ? "quiet" : nil)
|
105
|
+
].flatten.compact
|
106
|
+
tags.any? ? "[#{tags.join("] [")}]" : nil
|
107
|
+
end
|
108
|
+
|
109
|
+
def time_ago(timestamp)
|
110
|
+
seconds = Time.now - Time.at(timestamp)
|
111
|
+
return "just now" if seconds < 60
|
112
|
+
return "a minute ago" if seconds < 120
|
113
|
+
return "#{seconds.floor / 60} minutes ago" if seconds < 3600
|
114
|
+
return "an hour ago" if seconds < 7200
|
115
|
+
"#{seconds.floor / 60 / 60} hours ago"
|
116
|
+
end
|
117
|
+
|
118
|
+
QUEUE_STRUCT = Struct.new(:name, :size, :latency)
|
119
|
+
def queue_data
|
120
|
+
@queue_data ||= Sidekiq::Queue.all.map { |q|
|
121
|
+
QUEUE_STRUCT.new(q.name, q.size.to_s, sprintf("%#.2f", q.latency))
|
122
|
+
}
|
123
|
+
end
|
124
|
+
|
125
|
+
def process_set
|
126
|
+
@process_set ||= Sidekiq::ProcessSet.new
|
127
|
+
end
|
128
|
+
|
129
|
+
def stats
|
130
|
+
@stats ||= Sidekiq::Stats.new
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
data/lib/sidekiq/paginator.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Sidekiq
|
3
4
|
module Paginator
|
4
|
-
|
5
|
-
def page(key, pageidx=1, page_size=25, opts=nil)
|
5
|
+
def page(key, pageidx = 1, page_size = 25, opts = nil)
|
6
6
|
current_page = pageidx.to_i < 1 ? 1 : pageidx.to_i
|
7
7
|
pageidx = current_page - 1
|
8
8
|
total_size = 0
|
@@ -12,32 +12,36 @@ module Sidekiq
|
|
12
12
|
|
13
13
|
Sidekiq.redis do |conn|
|
14
14
|
type = conn.type(key)
|
15
|
+
rev = opts && opts[:reverse]
|
15
16
|
|
16
17
|
case type
|
17
|
-
when
|
18
|
-
|
19
|
-
|
20
|
-
conn.zcard(key)
|
18
|
+
when "zset"
|
19
|
+
total_size, items = conn.multi { |transaction|
|
20
|
+
transaction.zcard(key)
|
21
21
|
if rev
|
22
|
-
|
22
|
+
transaction.zrevrange(key, starting, ending, with_scores: true)
|
23
23
|
else
|
24
|
-
|
24
|
+
transaction.zrange(key, starting, ending, with_scores: true)
|
25
25
|
end
|
26
|
-
|
26
|
+
}
|
27
27
|
[current_page, total_size, items]
|
28
|
-
when
|
29
|
-
total_size, items = conn.multi
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
when "list"
|
29
|
+
total_size, items = conn.multi { |transaction|
|
30
|
+
transaction.llen(key)
|
31
|
+
if rev
|
32
|
+
transaction.lrange(key, -ending - 1, -starting - 1)
|
33
|
+
else
|
34
|
+
transaction.lrange(key, starting, ending)
|
35
|
+
end
|
36
|
+
}
|
37
|
+
items.reverse! if rev
|
33
38
|
[current_page, total_size, items]
|
34
|
-
when
|
39
|
+
when "none"
|
35
40
|
[1, 0, []]
|
36
41
|
else
|
37
42
|
raise "can't page a #{type}"
|
38
43
|
end
|
39
44
|
end
|
40
45
|
end
|
41
|
-
|
42
46
|
end
|
43
47
|
end
|