sidekiq 6.1.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 +7 -0
- data/.circleci/config.yml +71 -0
- data/.github/contributing.md +32 -0
- data/.github/issue_template.md +11 -0
- data/.gitignore +13 -0
- data/.standard.yml +20 -0
- data/3.0-Upgrade.md +70 -0
- data/4.0-Upgrade.md +53 -0
- data/5.0-Upgrade.md +56 -0
- data/6.0-Upgrade.md +72 -0
- data/COMM-LICENSE +97 -0
- data/Changes.md +1718 -0
- data/Ent-2.0-Upgrade.md +37 -0
- data/Ent-Changes.md +269 -0
- data/Gemfile +24 -0
- data/Gemfile.lock +208 -0
- data/LICENSE +9 -0
- data/Pro-2.0-Upgrade.md +138 -0
- data/Pro-3.0-Upgrade.md +44 -0
- data/Pro-4.0-Upgrade.md +35 -0
- data/Pro-5.0-Upgrade.md +25 -0
- data/Pro-Changes.md +790 -0
- data/README.md +94 -0
- data/Rakefile +10 -0
- data/bin/sidekiq +42 -0
- data/bin/sidekiqload +157 -0
- data/bin/sidekiqmon +8 -0
- data/code_of_conduct.md +50 -0
- data/lib/generators/sidekiq/templates/worker.rb.erb +9 -0
- data/lib/generators/sidekiq/templates/worker_spec.rb.erb +6 -0
- data/lib/generators/sidekiq/templates/worker_test.rb.erb +8 -0
- data/lib/generators/sidekiq/worker_generator.rb +57 -0
- data/lib/sidekiq.rb +262 -0
- data/lib/sidekiq/api.rb +960 -0
- data/lib/sidekiq/cli.rb +401 -0
- data/lib/sidekiq/client.rb +263 -0
- data/lib/sidekiq/delay.rb +41 -0
- data/lib/sidekiq/exception_handler.rb +27 -0
- data/lib/sidekiq/extensions/action_mailer.rb +47 -0
- data/lib/sidekiq/extensions/active_record.rb +43 -0
- data/lib/sidekiq/extensions/class_methods.rb +43 -0
- data/lib/sidekiq/extensions/generic_proxy.rb +31 -0
- data/lib/sidekiq/fetch.rb +82 -0
- data/lib/sidekiq/job_logger.rb +63 -0
- data/lib/sidekiq/job_retry.rb +262 -0
- data/lib/sidekiq/launcher.rb +206 -0
- data/lib/sidekiq/logger.rb +165 -0
- data/lib/sidekiq/manager.rb +135 -0
- data/lib/sidekiq/middleware/chain.rb +160 -0
- data/lib/sidekiq/middleware/i18n.rb +40 -0
- data/lib/sidekiq/monitor.rb +133 -0
- data/lib/sidekiq/paginator.rb +47 -0
- data/lib/sidekiq/processor.rb +280 -0
- data/lib/sidekiq/rails.rb +50 -0
- data/lib/sidekiq/redis_connection.rb +146 -0
- data/lib/sidekiq/scheduled.rb +173 -0
- data/lib/sidekiq/sd_notify.rb +149 -0
- data/lib/sidekiq/systemd.rb +24 -0
- data/lib/sidekiq/testing.rb +344 -0
- data/lib/sidekiq/testing/inline.rb +30 -0
- data/lib/sidekiq/util.rb +67 -0
- data/lib/sidekiq/version.rb +5 -0
- data/lib/sidekiq/web.rb +213 -0
- data/lib/sidekiq/web/action.rb +93 -0
- data/lib/sidekiq/web/application.rb +357 -0
- data/lib/sidekiq/web/csrf_protection.rb +153 -0
- data/lib/sidekiq/web/helpers.rb +333 -0
- data/lib/sidekiq/web/router.rb +101 -0
- data/lib/sidekiq/worker.rb +244 -0
- data/sidekiq.gemspec +20 -0
- data/web/assets/images/favicon.ico +0 -0
- data/web/assets/images/logo.png +0 -0
- data/web/assets/images/status.png +0 -0
- data/web/assets/javascripts/application.js +95 -0
- data/web/assets/javascripts/dashboard.js +296 -0
- data/web/assets/stylesheets/application-dark.css +133 -0
- data/web/assets/stylesheets/application-rtl.css +246 -0
- data/web/assets/stylesheets/application.css +1158 -0
- data/web/assets/stylesheets/bootstrap-rtl.min.css +9 -0
- data/web/assets/stylesheets/bootstrap.css +5 -0
- data/web/locales/ar.yml +81 -0
- data/web/locales/cs.yml +78 -0
- data/web/locales/da.yml +68 -0
- data/web/locales/de.yml +81 -0
- data/web/locales/el.yml +68 -0
- data/web/locales/en.yml +83 -0
- data/web/locales/es.yml +70 -0
- data/web/locales/fa.yml +80 -0
- data/web/locales/fr.yml +78 -0
- data/web/locales/he.yml +79 -0
- data/web/locales/hi.yml +75 -0
- data/web/locales/it.yml +69 -0
- data/web/locales/ja.yml +83 -0
- data/web/locales/ko.yml +68 -0
- data/web/locales/lt.yml +83 -0
- data/web/locales/nb.yml +77 -0
- data/web/locales/nl.yml +68 -0
- data/web/locales/pl.yml +59 -0
- data/web/locales/pt-br.yml +68 -0
- data/web/locales/pt.yml +67 -0
- data/web/locales/ru.yml +78 -0
- data/web/locales/sv.yml +68 -0
- data/web/locales/ta.yml +75 -0
- data/web/locales/uk.yml +76 -0
- data/web/locales/ur.yml +80 -0
- data/web/locales/vi.yml +83 -0
- data/web/locales/zh-cn.yml +68 -0
- data/web/locales/zh-tw.yml +68 -0
- data/web/views/_footer.erb +20 -0
- data/web/views/_job_info.erb +89 -0
- data/web/views/_nav.erb +52 -0
- data/web/views/_paging.erb +23 -0
- data/web/views/_poll_link.erb +7 -0
- data/web/views/_status.erb +4 -0
- data/web/views/_summary.erb +40 -0
- data/web/views/busy.erb +101 -0
- data/web/views/dashboard.erb +75 -0
- data/web/views/dead.erb +34 -0
- data/web/views/layout.erb +41 -0
- data/web/views/morgue.erb +78 -0
- data/web/views/queue.erb +55 -0
- data/web/views/queues.erb +38 -0
- data/web/views/retries.erb +83 -0
- data/web/views/retry.erb +34 -0
- data/web/views/scheduled.erb +57 -0
- data/web/views/scheduled_job_info.erb +8 -0
- metadata +212 -0
@@ -0,0 +1,153 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# this file originally based on authenticity_token.rb from the sinatra/rack-protection project
|
4
|
+
#
|
5
|
+
# The MIT License (MIT)
|
6
|
+
#
|
7
|
+
# Copyright (c) 2011-2017 Konstantin Haase
|
8
|
+
# Copyright (c) 2015-2017 Zachary Scott
|
9
|
+
#
|
10
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
11
|
+
# a copy of this software and associated documentation files (the
|
12
|
+
# 'Software'), to deal in the Software without restriction, including
|
13
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
14
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
15
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
16
|
+
# the following conditions:
|
17
|
+
#
|
18
|
+
# The above copyright notice and this permission notice shall be
|
19
|
+
# included in all copies or substantial portions of the Software.
|
20
|
+
#
|
21
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
22
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
23
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
24
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
25
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
26
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
27
|
+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
28
|
+
|
29
|
+
require "securerandom"
|
30
|
+
require "base64"
|
31
|
+
require "rack/request"
|
32
|
+
|
33
|
+
module Sidekiq
|
34
|
+
class Web
|
35
|
+
class CsrfProtection
|
36
|
+
def initialize(app, options = nil)
|
37
|
+
@app = app
|
38
|
+
end
|
39
|
+
|
40
|
+
def call(env)
|
41
|
+
accept?(env) ? admit(env) : deny(env)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def admit(env)
|
47
|
+
# On each successful request, we create a fresh masked token
|
48
|
+
# which will be used in any forms rendered for this request.
|
49
|
+
s = session(env)
|
50
|
+
s[:csrf] ||= SecureRandom.base64(TOKEN_LENGTH)
|
51
|
+
env[:csrf_token] = mask_token(s[:csrf])
|
52
|
+
@app.call(env)
|
53
|
+
end
|
54
|
+
|
55
|
+
def safe?(env)
|
56
|
+
%w[GET HEAD OPTIONS TRACE].include? env["REQUEST_METHOD"]
|
57
|
+
end
|
58
|
+
|
59
|
+
def logger(env)
|
60
|
+
@logger ||= (env["rack.logger"] || ::Logger.new(env["rack.errors"]))
|
61
|
+
end
|
62
|
+
|
63
|
+
def deny(env)
|
64
|
+
logger(env).warn "attack prevented by #{self.class}"
|
65
|
+
[403, {"Content-Type" => "text/plain"}, ["Forbidden"]]
|
66
|
+
end
|
67
|
+
|
68
|
+
def session(env)
|
69
|
+
env["rack.session"] || fail("you need to set up a session middleware *before* #{self.class}")
|
70
|
+
end
|
71
|
+
|
72
|
+
def accept?(env)
|
73
|
+
return true if safe?(env)
|
74
|
+
|
75
|
+
giventoken = Rack::Request.new(env).params["authenticity_token"]
|
76
|
+
valid_token?(env, giventoken)
|
77
|
+
end
|
78
|
+
|
79
|
+
TOKEN_LENGTH = 32
|
80
|
+
|
81
|
+
# Checks that the token given to us as a parameter matches
|
82
|
+
# the token stored in the session.
|
83
|
+
def valid_token?(env, giventoken)
|
84
|
+
return false if giventoken.nil? || giventoken.empty?
|
85
|
+
|
86
|
+
begin
|
87
|
+
token = decode_token(giventoken)
|
88
|
+
rescue ArgumentError # client input is invalid
|
89
|
+
return false
|
90
|
+
end
|
91
|
+
|
92
|
+
sess = session(env)
|
93
|
+
localtoken = sess[:csrf]
|
94
|
+
|
95
|
+
# Rotate the session token after every use
|
96
|
+
sess[:csrf] = SecureRandom.base64(TOKEN_LENGTH)
|
97
|
+
|
98
|
+
# See if it's actually a masked token or not. We should be able
|
99
|
+
# to handle any unmasked tokens that we've issued without error.
|
100
|
+
|
101
|
+
if unmasked_token?(token)
|
102
|
+
compare_with_real_token token, localtoken
|
103
|
+
elsif masked_token?(token)
|
104
|
+
unmasked = unmask_token(token)
|
105
|
+
compare_with_real_token unmasked, localtoken
|
106
|
+
else
|
107
|
+
false # Token is malformed
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# Creates a masked version of the authenticity token that varies
|
112
|
+
# on each request. The masking is used to mitigate SSL attacks
|
113
|
+
# like BREACH.
|
114
|
+
def mask_token(token)
|
115
|
+
token = decode_token(token)
|
116
|
+
one_time_pad = SecureRandom.random_bytes(token.length)
|
117
|
+
encrypted_token = xor_byte_strings(one_time_pad, token)
|
118
|
+
masked_token = one_time_pad + encrypted_token
|
119
|
+
Base64.strict_encode64(masked_token)
|
120
|
+
end
|
121
|
+
|
122
|
+
# Essentially the inverse of +mask_token+.
|
123
|
+
def unmask_token(masked_token)
|
124
|
+
# Split the token into the one-time pad and the encrypted
|
125
|
+
# value and decrypt it
|
126
|
+
token_length = masked_token.length / 2
|
127
|
+
one_time_pad = masked_token[0...token_length]
|
128
|
+
encrypted_token = masked_token[token_length..-1]
|
129
|
+
xor_byte_strings(one_time_pad, encrypted_token)
|
130
|
+
end
|
131
|
+
|
132
|
+
def unmasked_token?(token)
|
133
|
+
token.length == TOKEN_LENGTH
|
134
|
+
end
|
135
|
+
|
136
|
+
def masked_token?(token)
|
137
|
+
token.length == TOKEN_LENGTH * 2
|
138
|
+
end
|
139
|
+
|
140
|
+
def compare_with_real_token(token, local)
|
141
|
+
Rack::Utils.secure_compare(token.to_s, decode_token(local).to_s)
|
142
|
+
end
|
143
|
+
|
144
|
+
def decode_token(token)
|
145
|
+
Base64.strict_decode64(token)
|
146
|
+
end
|
147
|
+
|
148
|
+
def xor_byte_strings(s1, s2)
|
149
|
+
s1.bytes.zip(s2.bytes).map { |(c1, c2)| c1 ^ c2 }.pack("c*")
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
@@ -0,0 +1,333 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "uri"
|
4
|
+
require "set"
|
5
|
+
require "yaml"
|
6
|
+
require "cgi"
|
7
|
+
|
8
|
+
module Sidekiq
|
9
|
+
# This is not a public API
|
10
|
+
module WebHelpers
|
11
|
+
def strings(lang)
|
12
|
+
@strings ||= {}
|
13
|
+
@strings[lang] ||= begin
|
14
|
+
# Allow sidekiq-web extensions to add locale paths
|
15
|
+
# so extensions can be localized
|
16
|
+
settings.locales.each_with_object({}) do |path, global|
|
17
|
+
find_locale_files(lang).each do |file|
|
18
|
+
strs = YAML.load(File.open(file))
|
19
|
+
global.merge!(strs[lang])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def clear_caches
|
26
|
+
@strings = nil
|
27
|
+
@locale_files = nil
|
28
|
+
@available_locales = nil
|
29
|
+
end
|
30
|
+
|
31
|
+
def locale_files
|
32
|
+
@locale_files ||= settings.locales.flat_map { |path|
|
33
|
+
Dir["#{path}/*.yml"]
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def available_locales
|
38
|
+
@available_locales ||= locale_files.map { |path| File.basename(path, ".yml") }.uniq
|
39
|
+
end
|
40
|
+
|
41
|
+
def find_locale_files(lang)
|
42
|
+
locale_files.select { |file| file =~ /\/#{lang}\.yml$/ }
|
43
|
+
end
|
44
|
+
|
45
|
+
# This is a hook for a Sidekiq Pro feature. Please don't touch.
|
46
|
+
def filtering(*)
|
47
|
+
end
|
48
|
+
|
49
|
+
# This view helper provide ability display you html code in
|
50
|
+
# to head of page. Example:
|
51
|
+
#
|
52
|
+
# <% add_to_head do %>
|
53
|
+
# <link rel="stylesheet" .../>
|
54
|
+
# <meta .../>
|
55
|
+
# <% end %>
|
56
|
+
#
|
57
|
+
def add_to_head
|
58
|
+
@head_html ||= []
|
59
|
+
@head_html << yield.dup if block_given?
|
60
|
+
end
|
61
|
+
|
62
|
+
def display_custom_head
|
63
|
+
@head_html.join if defined?(@head_html)
|
64
|
+
end
|
65
|
+
|
66
|
+
def poll_path
|
67
|
+
if current_path != "" && params["poll"]
|
68
|
+
path = root_path + current_path
|
69
|
+
query_string = to_query_string(params.slice(*params.keys - %w[page poll]))
|
70
|
+
path += "?#{query_string}" unless query_string.empty?
|
71
|
+
path
|
72
|
+
else
|
73
|
+
""
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def text_direction
|
78
|
+
get_locale["TextDirection"] || "ltr"
|
79
|
+
end
|
80
|
+
|
81
|
+
def rtl?
|
82
|
+
text_direction == "rtl"
|
83
|
+
end
|
84
|
+
|
85
|
+
# See https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4
|
86
|
+
def user_preferred_languages
|
87
|
+
languages = env["HTTP_ACCEPT_LANGUAGE"]
|
88
|
+
languages.to_s.downcase.gsub(/\s+/, "").split(",").map { |language|
|
89
|
+
locale, quality = language.split(";q=", 2)
|
90
|
+
locale = nil if locale == "*" # Ignore wildcards
|
91
|
+
quality = quality ? quality.to_f : 1.0
|
92
|
+
[locale, quality]
|
93
|
+
}.sort { |(_, left), (_, right)|
|
94
|
+
right <=> left
|
95
|
+
}.map(&:first).compact
|
96
|
+
end
|
97
|
+
|
98
|
+
# Given an Accept-Language header like "fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4,ru;q=0.2"
|
99
|
+
# this method will try to best match the available locales to the user's preferred languages.
|
100
|
+
#
|
101
|
+
# Inspiration taken from https://github.com/iain/http_accept_language/blob/master/lib/http_accept_language/parser.rb
|
102
|
+
def locale
|
103
|
+
@locale ||= begin
|
104
|
+
matched_locale = user_preferred_languages.map { |preferred|
|
105
|
+
preferred_language = preferred.split("-", 2).first
|
106
|
+
|
107
|
+
lang_group = available_locales.select { |available|
|
108
|
+
preferred_language == available.split("-", 2).first
|
109
|
+
}
|
110
|
+
|
111
|
+
lang_group.find { |lang| lang == preferred } || lang_group.min_by(&:length)
|
112
|
+
}.compact.first
|
113
|
+
|
114
|
+
matched_locale || "en"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# within is used by Sidekiq Pro
|
119
|
+
def display_tags(job, within = nil)
|
120
|
+
job.tags.map { |tag|
|
121
|
+
"<span class='jobtag label label-info'>#{::Rack::Utils.escape_html(tag)}</span>"
|
122
|
+
}.join(" ")
|
123
|
+
end
|
124
|
+
|
125
|
+
# mperham/sidekiq#3243
|
126
|
+
def unfiltered?
|
127
|
+
yield unless env["PATH_INFO"].start_with?("/filter/")
|
128
|
+
end
|
129
|
+
|
130
|
+
def get_locale
|
131
|
+
strings(locale)
|
132
|
+
end
|
133
|
+
|
134
|
+
def t(msg, options = {})
|
135
|
+
string = get_locale[msg] || strings("en")[msg] || msg
|
136
|
+
if options.empty?
|
137
|
+
string
|
138
|
+
else
|
139
|
+
string % options
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def sort_direction_label
|
144
|
+
params[:direction] == "asc" ? "↑" : "↓"
|
145
|
+
end
|
146
|
+
|
147
|
+
def workers
|
148
|
+
@workers ||= Sidekiq::Workers.new
|
149
|
+
end
|
150
|
+
|
151
|
+
def processes
|
152
|
+
@processes ||= Sidekiq::ProcessSet.new
|
153
|
+
end
|
154
|
+
|
155
|
+
def stats
|
156
|
+
@stats ||= Sidekiq::Stats.new
|
157
|
+
end
|
158
|
+
|
159
|
+
def redis_connection
|
160
|
+
Sidekiq.redis do |conn|
|
161
|
+
c = conn.connection
|
162
|
+
"redis://#{c[:location]}/#{c[:db]}"
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def namespace
|
167
|
+
@ns ||= Sidekiq.redis { |conn| conn.respond_to?(:namespace) ? conn.namespace : nil }
|
168
|
+
end
|
169
|
+
|
170
|
+
def redis_info
|
171
|
+
Sidekiq.redis_info
|
172
|
+
end
|
173
|
+
|
174
|
+
def root_path
|
175
|
+
"#{env["SCRIPT_NAME"]}/"
|
176
|
+
end
|
177
|
+
|
178
|
+
def current_path
|
179
|
+
@current_path ||= request.path_info.gsub(/^\//, "")
|
180
|
+
end
|
181
|
+
|
182
|
+
def current_status
|
183
|
+
workers.size == 0 ? "idle" : "active"
|
184
|
+
end
|
185
|
+
|
186
|
+
def relative_time(time)
|
187
|
+
stamp = time.getutc.iso8601
|
188
|
+
%(<time class="ltr" dir="ltr" title="#{stamp}" datetime="#{stamp}">#{time}</time>)
|
189
|
+
end
|
190
|
+
|
191
|
+
def job_params(job, score)
|
192
|
+
"#{score}-#{job["jid"]}"
|
193
|
+
end
|
194
|
+
|
195
|
+
def parse_params(params)
|
196
|
+
score, jid = params.split("-", 2)
|
197
|
+
[score.to_f, jid]
|
198
|
+
end
|
199
|
+
|
200
|
+
SAFE_QPARAMS = %w[page poll direction]
|
201
|
+
|
202
|
+
# Merge options with current params, filter safe params, and stringify to query string
|
203
|
+
def qparams(options)
|
204
|
+
stringified_options = options.transform_keys(&:to_s)
|
205
|
+
|
206
|
+
to_query_string(params.merge(stringified_options))
|
207
|
+
end
|
208
|
+
|
209
|
+
def to_query_string(params)
|
210
|
+
params.map { |key, value|
|
211
|
+
SAFE_QPARAMS.include?(key) ? "#{key}=#{CGI.escape(value.to_s)}" : next
|
212
|
+
}.compact.join("&")
|
213
|
+
end
|
214
|
+
|
215
|
+
def truncate(text, truncate_after_chars = 2000)
|
216
|
+
truncate_after_chars && text.size > truncate_after_chars ? "#{text[0..truncate_after_chars]}..." : text
|
217
|
+
end
|
218
|
+
|
219
|
+
def display_args(args, truncate_after_chars = 2000)
|
220
|
+
return "Invalid job payload, args is nil" if args.nil?
|
221
|
+
return "Invalid job payload, args must be an Array, not #{args.class.name}" unless args.is_a?(Array)
|
222
|
+
|
223
|
+
begin
|
224
|
+
args.map { |arg|
|
225
|
+
h(truncate(to_display(arg), truncate_after_chars))
|
226
|
+
}.join(", ")
|
227
|
+
rescue
|
228
|
+
"Illegal job arguments: #{h args.inspect}"
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
def csrf_tag
|
233
|
+
"<input type='hidden' name='authenticity_token' value='#{env[:csrf_token]}'/>"
|
234
|
+
end
|
235
|
+
|
236
|
+
def to_display(arg)
|
237
|
+
arg.inspect
|
238
|
+
rescue
|
239
|
+
begin
|
240
|
+
arg.to_s
|
241
|
+
rescue => ex
|
242
|
+
"Cannot display argument: [#{ex.class.name}] #{ex.message}"
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
RETRY_JOB_KEYS = Set.new(%w[
|
247
|
+
queue class args retry_count retried_at failed_at
|
248
|
+
jid error_message error_class backtrace
|
249
|
+
error_backtrace enqueued_at retry wrapped
|
250
|
+
created_at tags
|
251
|
+
])
|
252
|
+
|
253
|
+
def retry_extra_items(retry_job)
|
254
|
+
@retry_extra_items ||= {}.tap do |extra|
|
255
|
+
retry_job.item.each do |key, value|
|
256
|
+
extra[key] = value unless RETRY_JOB_KEYS.include?(key)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
def number_with_delimiter(number)
|
262
|
+
begin
|
263
|
+
Float(number)
|
264
|
+
rescue ArgumentError, TypeError
|
265
|
+
return number
|
266
|
+
end
|
267
|
+
|
268
|
+
options = {delimiter: ",", separator: "."}
|
269
|
+
parts = number.to_s.to_str.split(".")
|
270
|
+
parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{options[:delimiter]}")
|
271
|
+
parts.join(options[:separator])
|
272
|
+
end
|
273
|
+
|
274
|
+
def h(text)
|
275
|
+
::Rack::Utils.escape_html(text)
|
276
|
+
rescue ArgumentError => e
|
277
|
+
raise unless e.message.eql?("invalid byte sequence in UTF-8")
|
278
|
+
text.encode!("UTF-16", "UTF-8", invalid: :replace, replace: "").encode!("UTF-8", "UTF-16")
|
279
|
+
retry
|
280
|
+
end
|
281
|
+
|
282
|
+
# Any paginated list that performs an action needs to redirect
|
283
|
+
# back to the proper page after performing that action.
|
284
|
+
def redirect_with_query(url)
|
285
|
+
r = request.referer
|
286
|
+
if r && r =~ /\?/
|
287
|
+
ref = URI(r)
|
288
|
+
redirect("#{url}?#{ref.query}")
|
289
|
+
else
|
290
|
+
redirect url
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
def environment_title_prefix
|
295
|
+
environment = Sidekiq.options[:environment] || ENV["APP_ENV"] || ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
|
296
|
+
|
297
|
+
"[#{environment.upcase}] " unless environment == "production"
|
298
|
+
end
|
299
|
+
|
300
|
+
def product_version
|
301
|
+
"Sidekiq v#{Sidekiq::VERSION}"
|
302
|
+
end
|
303
|
+
|
304
|
+
def server_utc_time
|
305
|
+
Time.now.utc.strftime("%H:%M:%S UTC")
|
306
|
+
end
|
307
|
+
|
308
|
+
def redis_connection_and_namespace
|
309
|
+
@redis_connection_and_namespace ||= begin
|
310
|
+
namespace_suffix = namespace.nil? ? "" : "##{namespace}"
|
311
|
+
"#{redis_connection}#{namespace_suffix}"
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
def retry_or_delete_or_kill(job, params)
|
316
|
+
if params["retry"]
|
317
|
+
job.retry
|
318
|
+
elsif params["delete"]
|
319
|
+
job.delete
|
320
|
+
elsif params["kill"]
|
321
|
+
job.kill
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
def delete_or_add_queue(job, params)
|
326
|
+
if params["delete"]
|
327
|
+
job.delete
|
328
|
+
elsif params["add_to_queue"]
|
329
|
+
job.add_to_queue
|
330
|
+
end
|
331
|
+
end
|
332
|
+
end
|
333
|
+
end
|