sidekiq 5.2.10 → 6.0.0.pre1

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.

Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.standard.yml +20 -0
  3. data/.travis.yml +5 -2
  4. data/6.0-Upgrade.md +58 -0
  5. data/Changes.md +21 -16
  6. data/Gemfile +15 -10
  7. data/Rakefile +5 -4
  8. data/bin/sidekiqctl +1 -10
  9. data/lib/generators/sidekiq/worker_generator.rb +12 -14
  10. data/lib/sidekiq/api.rb +133 -148
  11. data/lib/sidekiq/cli.rb +95 -147
  12. data/lib/sidekiq/client.rb +44 -45
  13. data/lib/sidekiq/ctl.rb +35 -109
  14. data/lib/sidekiq/delay.rb +5 -6
  15. data/lib/sidekiq/exception_handler.rb +10 -12
  16. data/lib/sidekiq/extensions/action_mailer.rb +10 -20
  17. data/lib/sidekiq/extensions/active_record.rb +9 -7
  18. data/lib/sidekiq/extensions/class_methods.rb +9 -7
  19. data/lib/sidekiq/extensions/generic_proxy.rb +4 -4
  20. data/lib/sidekiq/fetch.rb +5 -6
  21. data/lib/sidekiq/job_logger.rb +37 -7
  22. data/lib/sidekiq/job_retry.rb +45 -58
  23. data/lib/sidekiq/launcher.rb +59 -48
  24. data/lib/sidekiq/logger.rb +69 -0
  25. data/lib/sidekiq/manager.rb +6 -8
  26. data/lib/sidekiq/middleware/chain.rb +2 -1
  27. data/lib/sidekiq/middleware/i18n.rb +5 -7
  28. data/lib/sidekiq/paginator.rb +11 -12
  29. data/lib/sidekiq/processor.rb +42 -45
  30. data/lib/sidekiq/rails.rb +2 -26
  31. data/lib/sidekiq/redis_connection.rb +31 -37
  32. data/lib/sidekiq/scheduled.rb +17 -19
  33. data/lib/sidekiq/testing/inline.rb +2 -1
  34. data/lib/sidekiq/testing.rb +22 -23
  35. data/lib/sidekiq/util.rb +18 -15
  36. data/lib/sidekiq/version.rb +2 -1
  37. data/lib/sidekiq/web/action.rb +15 -11
  38. data/lib/sidekiq/web/application.rb +59 -59
  39. data/lib/sidekiq/web/helpers.rb +66 -67
  40. data/lib/sidekiq/web/router.rb +17 -14
  41. data/lib/sidekiq/web.rb +36 -44
  42. data/lib/sidekiq/worker.rb +12 -13
  43. data/lib/sidekiq.rb +53 -42
  44. data/sidekiq.gemspec +7 -7
  45. metadata +20 -32
  46. data/lib/sidekiq/core_ext.rb +0 -1
  47. data/lib/sidekiq/logging.rb +0 -122
  48. data/lib/sidekiq/middleware/server/active_record.rb +0 -23
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Sidekiq
4
4
  class WebAction
5
- RACK_SESSION = 'rack.session'
5
+ RACK_SESSION = "rack.session"
6
6
 
7
7
  attr_accessor :env, :block, :type
8
8
 
@@ -15,18 +15,18 @@ module Sidekiq
15
15
  end
16
16
 
17
17
  def halt(res)
18
- throw :halt, [res, {"Content-Type" => "text/plain"}, [res.to_s]]
18
+ throw :halt, res
19
19
  end
20
20
 
21
21
  def redirect(location)
22
- throw :halt, [302, { "Location" => "#{request.base_url}#{location}" }, []]
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.kind_of? Symbol
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("def _erb_#{content}\n#{src}\n end")
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, { "Content-Type" => "application/json", "Cache-Control" => "no-cache" }, [Sidekiq.dump_json(payload)]]
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
- @@files ||= {}
78
+ @files ||= {}
75
79
  end
76
80
 
77
81
  private
78
82
 
79
83
  def _erb(file, locals)
80
- locals.each {|k, v| define_singleton_method(k){ v } unless (singleton_methods.include? k)} if locals
84
+ locals&.each {|k, v| define_singleton_method(k) { v } unless singleton_methods.include? k}
81
85
 
82
- if file.kind_of?(String)
86
+ if file.is_a?(String)
83
87
  ERB.new(file).result(binding)
84
88
  else
85
89
  send(:"_erb_#{file}")
@@ -6,7 +6,7 @@ module Sidekiq
6
6
 
7
7
  CONTENT_LENGTH = "Content-Length"
8
8
  CONTENT_TYPE = "Content-Type"
9
- REDIS_KEYS = %w(redis_version uptime_in_days connected_clients used_memory_human used_memory_peak_human)
9
+ REDIS_KEYS = %w[redis_version uptime_in_days connected_clients used_memory_human used_memory_peak_human]
10
10
  CSP_HEADER = [
11
11
  "default-src 'self' https: http:",
12
12
  "child-src 'self'",
@@ -20,8 +20,8 @@ module Sidekiq
20
20
  "script-src 'self' https: http: 'unsafe-inline'",
21
21
  "style-src 'self' https: http: 'unsafe-inline'",
22
22
  "worker-src 'self'",
23
- "base-uri 'self'"
24
- ].join('; ').freeze
23
+ "base-uri 'self'",
24
+ ].join("; ").freeze
25
25
 
26
26
  def initialize(klass)
27
27
  @klass = klass
@@ -44,11 +44,8 @@ module Sidekiq
44
44
  end
45
45
 
46
46
  get "/" do
47
- @redis_info = redis_info.select{ |k, v| REDIS_KEYS.include? k }
48
- days = (params["days"] || 30).to_i
49
- return halt(401) if days < 1 || days > 180
50
-
51
- stats_history = Sidekiq::Stats::History.new(days)
47
+ @redis_info = redis_info.select { |k, v| REDIS_KEYS.include? k }
48
+ stats_history = Sidekiq::Stats::History.new((params["days"] || 30).to_i)
52
49
  @processed_history = stats_history.processed
53
50
  @failed_history = stats_history.failed
54
51
 
@@ -60,14 +57,14 @@ module Sidekiq
60
57
  end
61
58
 
62
59
  post "/busy" do
63
- if params['identity']
64
- p = Sidekiq::Process.new('identity' => params['identity'])
65
- p.quiet! if params['quiet']
66
- p.stop! if params['stop']
60
+ if params["identity"]
61
+ p = Sidekiq::Process.new("identity" => params["identity"])
62
+ p.quiet! if params["quiet"]
63
+ p.stop! if params["stop"]
67
64
  else
68
65
  processes.each do |pro|
69
- pro.quiet! if params['quiet']
70
- pro.stop! if params['stop']
66
+ pro.quiet! if params["quiet"]
67
+ pro.stop! if params["stop"]
71
68
  end
72
69
  end
73
70
 
@@ -85,9 +82,9 @@ module Sidekiq
85
82
 
86
83
  halt(404) unless @name
87
84
 
88
- @count = (params['count'] || 25).to_i
85
+ @count = (params["count"] || 25).to_i
89
86
  @queue = Sidekiq::Queue.new(@name)
90
- (@current_page, @total_size, @messages) = page("queue:#{@name}", params['page'], @count)
87
+ (@current_page, @total_size, @messages) = page("queue:#{@name}", params["page"], @count)
91
88
  @messages = @messages.map { |msg| Sidekiq::Job.new(msg, @name) }
92
89
 
93
90
  erb(:queue)
@@ -101,21 +98,22 @@ module Sidekiq
101
98
 
102
99
  post "/queues/:name/delete" do
103
100
  name = route_params[:name]
104
- Sidekiq::Job.new(params['key_val'], name).delete
101
+ Sidekiq::Job.new(params["key_val"], name).delete
105
102
 
106
103
  redirect_with_query("#{root_path}queues/#{CGI.escape(name)}")
107
104
  end
108
105
 
109
- get '/morgue' do
110
- @count = (params['count'] || 25).to_i
111
- (@current_page, @total_size, @dead) = page("dead", params['page'], @count, reverse: true)
106
+ get "/morgue" do
107
+ @count = (params["count"] || 25).to_i
108
+ (@current_page, @total_size, @dead) = page("dead", params["page"], @count, reverse: true)
112
109
  @dead = @dead.map { |msg, score| Sidekiq::SortedEntry.new(nil, score, msg) }
113
110
 
114
111
  erb(:morgue)
115
112
  end
116
113
 
117
114
  get "/morgue/:key" do
118
- halt(404) unless key = route_params[:key]
115
+ key = route_params[:key]
116
+ halt(404) unless key
119
117
 
120
118
  @dead = Sidekiq::DeadSet.new.fetch(*parse_params(key)).first
121
119
 
@@ -126,10 +124,10 @@ module Sidekiq
126
124
  end
127
125
  end
128
126
 
129
- post '/morgue' do
130
- redirect(request.path) unless params['key']
127
+ post "/morgue" do
128
+ redirect(request.path) unless params["key"]
131
129
 
132
- params['key'].each do |key|
130
+ params["key"].each do |key|
133
131
  job = Sidekiq::DeadSet.new.fetch(*parse_params(key)).first
134
132
  retry_or_delete_or_kill job, params if job
135
133
  end
@@ -150,7 +148,8 @@ module Sidekiq
150
148
  end
151
149
 
152
150
  post "/morgue/:key" do
153
- halt(404) unless key = route_params[:key]
151
+ key = route_params[:key]
152
+ halt(404) unless key
154
153
 
155
154
  job = Sidekiq::DeadSet.new.fetch(*parse_params(key)).first
156
155
  retry_or_delete_or_kill job, params if job
@@ -158,9 +157,9 @@ module Sidekiq
158
157
  redirect_with_query("#{root_path}morgue")
159
158
  end
160
159
 
161
- get '/retries' do
162
- @count = (params['count'] || 25).to_i
163
- (@current_page, @total_size, @retries) = page("retry", params['page'], @count)
160
+ get "/retries" do
161
+ @count = (params["count"] || 25).to_i
162
+ (@current_page, @total_size, @retries) = page("retry", params["page"], @count)
164
163
  @retries = @retries.map { |msg, score| Sidekiq::SortedEntry.new(nil, score, msg) }
165
164
 
166
165
  erb(:retries)
@@ -176,10 +175,10 @@ module Sidekiq
176
175
  end
177
176
  end
178
177
 
179
- post '/retries' do
180
- redirect(request.path) unless params['key']
178
+ post "/retries" do
179
+ redirect(request.path) unless params["key"]
181
180
 
182
- params['key'].each do |key|
181
+ params["key"].each do |key|
183
182
  job = Sidekiq::RetrySet.new.fetch(*parse_params(key)).first
184
183
  retry_or_delete_or_kill job, params if job
185
184
  end
@@ -213,9 +212,9 @@ module Sidekiq
213
212
  redirect_with_query("#{root_path}retries")
214
213
  end
215
214
 
216
- get '/scheduled' do
217
- @count = (params['count'] || 25).to_i
218
- (@current_page, @total_size, @scheduled) = page("schedule", params['page'], @count)
215
+ get "/scheduled" do
216
+ @count = (params["count"] || 25).to_i
217
+ (@current_page, @total_size, @scheduled) = page("schedule", params["page"], @count)
219
218
  @scheduled = @scheduled.map { |msg, score| Sidekiq::SortedEntry.new(nil, score, msg) }
220
219
 
221
220
  erb(:scheduled)
@@ -231,10 +230,10 @@ module Sidekiq
231
230
  end
232
231
  end
233
232
 
234
- post '/scheduled' do
235
- redirect(request.path) unless params['key']
233
+ post "/scheduled" do
234
+ redirect(request.path) unless params["key"]
236
235
 
237
- params['key'].each do |key|
236
+ params["key"].each do |key|
238
237
  job = Sidekiq::ScheduledSet.new.fetch(*parse_params(key)).first
239
238
  delete_or_add_queue job, params if job
240
239
  end
@@ -243,7 +242,8 @@ module Sidekiq
243
242
  end
244
243
 
245
244
  post "/scheduled/:key" do
246
- halt(404) unless key = route_params[:key]
245
+ key = route_params[:key]
246
+ halt(404) unless key
247
247
 
248
248
  job = Sidekiq::ScheduledSet.new.fetch(*parse_params(key)).first
249
249
  delete_or_add_queue job, params if job
@@ -251,39 +251,39 @@ module Sidekiq
251
251
  redirect_with_query("#{root_path}scheduled")
252
252
  end
253
253
 
254
- get '/dashboard/stats' do
254
+ get "/dashboard/stats" do
255
255
  redirect "#{root_path}stats"
256
256
  end
257
257
 
258
- get '/stats' do
258
+ get "/stats" do
259
259
  sidekiq_stats = Sidekiq::Stats.new
260
260
  redis_stats = redis_info.select { |k, v| REDIS_KEYS.include? k }
261
261
  json(
262
262
  sidekiq: {
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
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,
272
272
  },
273
273
  redis: redis_stats,
274
274
  server_utc_time: server_utc_time
275
275
  )
276
276
  end
277
277
 
278
- get '/stats/queues' do
278
+ get "/stats/queues" do
279
279
  json Sidekiq::Stats::Queues.new.lengths
280
280
  end
281
281
 
282
282
  def call(env)
283
283
  action = self.class.match(env)
284
- return [404, {"Content-Type" => "text/plain", "X-Cascade" => "pass" }, ["Not Found"]] unless action
284
+ return [404, {"Content-Type" => "text/plain", "X-Cascade" => "pass"}, ["Not Found"]] unless action
285
285
 
286
- resp = catch(:halt) do
286
+ resp = catch(:halt) {
287
287
  app = @klass
288
288
  self.class.run_befores(app, action)
289
289
  begin
@@ -293,7 +293,7 @@ module Sidekiq
293
293
  end
294
294
 
295
295
  resp
296
- end
296
+ }
297
297
 
298
298
  resp = case resp
299
299
  when Array
@@ -303,7 +303,7 @@ module Sidekiq
303
303
  "Content-Type" => "text/html",
304
304
  "Cache-Control" => "no-cache",
305
305
  "Content-Language" => action.locale,
306
- "Content-Security-Policy" => CSP_HEADER
306
+ "Content-Security-Policy" => CSP_HEADER,
307
307
  }
308
308
 
309
309
  [200, headers, [resp]]
@@ -316,7 +316,7 @@ module Sidekiq
316
316
  resp
317
317
  end
318
318
 
319
- def self.helpers(mod=nil, &block)
319
+ def self.helpers(mod = nil, &block)
320
320
  if block_given?
321
321
  WebAction.class_eval(&block)
322
322
  else
@@ -324,11 +324,11 @@ module Sidekiq
324
324
  end
325
325
  end
326
326
 
327
- def self.before(path=nil, &block)
327
+ def self.before(path = nil, &block)
328
328
  befores << [path && Regexp.new("\\A#{path.gsub("*", ".*")}\\z"), block]
329
329
  end
330
330
 
331
- def self.after(path=nil, &block)
331
+ def self.after(path = nil, &block)
332
332
  afters << [path && Regexp.new("\\A#{path.gsub("*", ".*")}\\z"), block]
333
333
  end
334
334
 
@@ -341,8 +341,8 @@ module Sidekiq
341
341
  end
342
342
 
343
343
  def self.run_hooks(hooks, app, action)
344
- hooks.select { |p,_| !p || p =~ action.env[WebRouter::PATH_INFO] }.
345
- each {|_,b| action.instance_exec(action.env, app, &b) }
344
+ hooks.select { |p, _| !p || p =~ action.env[WebRouter::PATH_INFO] }
345
+ .each {|_, b| action.instance_exec(action.env, app, &b) }
346
346
  end
347
347
 
348
348
  def self.befores
@@ -1,15 +1,16 @@
1
1
  # frozen_string_literal: true
2
- require 'uri'
3
- require 'set'
4
- require 'yaml'
5
- require 'cgi'
2
+
3
+ require "uri"
4
+ require "set"
5
+ require "yaml"
6
+ require "cgi"
6
7
 
7
8
  module Sidekiq
8
9
  # This is not a public API
9
10
  module WebHelpers
10
11
  def strings(lang)
11
- @@strings ||= {}
12
- @@strings[lang] ||= begin
12
+ @strings ||= {}
13
+ @strings[lang] ||= begin
13
14
  # Allow sidekiq-web extensions to add locale paths
14
15
  # so extensions can be localized
15
16
  settings.locales.each_with_object({}) do |path, global|
@@ -22,19 +23,19 @@ module Sidekiq
22
23
  end
23
24
 
24
25
  def clear_caches
25
- @@strings = nil
26
- @@locale_files = nil
27
- @@available_locales = nil
26
+ @strings = nil
27
+ @locale_files = nil
28
+ @available_locales = nil
28
29
  end
29
30
 
30
31
  def locale_files
31
- @@locale_files ||= settings.locales.flat_map do |path|
32
+ @locale_files ||= settings.locales.flat_map { |path|
32
33
  Dir["#{path}/*.yml"]
33
- end
34
+ }
34
35
  end
35
36
 
36
37
  def available_locales
37
- @@available_locales ||= locale_files.map { |path| File.basename(path, '.yml') }.uniq
38
+ @available_locales ||= locale_files.map { |path| File.basename(path, ".yml") }.uniq
38
39
  end
39
40
 
40
41
  def find_locale_files(lang)
@@ -63,7 +64,7 @@ module Sidekiq
63
64
  end
64
65
 
65
66
  def poll_path
66
- if current_path != '' && params['poll']
67
+ if current_path != "" && params["poll"]
67
68
  root_path + current_path
68
69
  else
69
70
  ""
@@ -71,24 +72,24 @@ module Sidekiq
71
72
  end
72
73
 
73
74
  def text_direction
74
- get_locale['TextDirection'] || 'ltr'
75
+ get_locale["TextDirection"] || "ltr"
75
76
  end
76
77
 
77
78
  def rtl?
78
- text_direction == 'rtl'
79
+ text_direction == "rtl"
79
80
  end
80
81
 
81
82
  # See https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4
82
83
  def user_preferred_languages
83
- languages = env['HTTP_ACCEPT_LANGUAGE']
84
- languages.to_s.downcase.gsub(/\s+/, '').split(',').map do |language|
85
- locale, quality = language.split(';q=', 2)
86
- locale = nil if locale == '*' # Ignore wildcards
84
+ languages = env["HTTP_ACCEPT_LANGUAGE"]
85
+ languages.to_s.downcase.gsub(/\s+/, "").split(",").map { |language|
86
+ locale, quality = language.split(";q=", 2)
87
+ locale = nil if locale == "*" # Ignore wildcards
87
88
  quality = quality ? quality.to_f : 1.0
88
89
  [locale, quality]
89
- end.sort do |(_, left), (_, right)|
90
+ }.sort { |(_, left), (_, right)|
90
91
  right <=> left
91
- end.map(&:first).compact
92
+ }.map(&:first).compact
92
93
  end
93
94
 
94
95
  # 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"
@@ -97,31 +98,31 @@ module Sidekiq
97
98
  # Inspiration taken from https://github.com/iain/http_accept_language/blob/master/lib/http_accept_language/parser.rb
98
99
  def locale
99
100
  @locale ||= begin
100
- matched_locale = user_preferred_languages.map do |preferred|
101
- preferred_language = preferred.split('-', 2).first
101
+ matched_locale = user_preferred_languages.map { |preferred|
102
+ preferred_language = preferred.split("-", 2).first
102
103
 
103
- lang_group = available_locales.select do |available|
104
- preferred_language == available.split('-', 2).first
105
- end
104
+ lang_group = available_locales.select { |available|
105
+ preferred_language == available.split("-", 2).first
106
+ }
106
107
 
107
108
  lang_group.find { |lang| lang == preferred } || lang_group.min_by(&:length)
108
- end.compact.first
109
+ }.compact.first
109
110
 
110
- matched_locale || 'en'
111
+ matched_locale || "en"
111
112
  end
112
113
  end
113
114
 
114
115
  # mperham/sidekiq#3243
115
116
  def unfiltered?
116
- yield unless env['PATH_INFO'].start_with?("/filter/")
117
+ yield unless env["PATH_INFO"].start_with?("/filter/")
117
118
  end
118
119
 
119
120
  def get_locale
120
121
  strings(locale)
121
122
  end
122
123
 
123
- def t(msg, options={})
124
- string = get_locale[msg] || strings('en')[msg] || msg
124
+ def t(msg, options = {})
125
+ string = get_locale[msg] || strings("en")[msg] || msg
125
126
  if options.empty?
126
127
  string
127
128
  else
@@ -142,9 +143,9 @@ module Sidekiq
142
143
  end
143
144
 
144
145
  def retries_with_score(score)
145
- Sidekiq.redis do |conn|
146
- conn.zrangebyscore('retry', score, score)
147
- end.map { |msg| Sidekiq.load_json(msg) }
146
+ Sidekiq.redis { |conn|
147
+ conn.zrangebyscore("retry", score, score)
148
+ }.map { |msg| Sidekiq.load_json(msg) }
148
149
  end
149
150
 
150
151
  def redis_connection
@@ -163,24 +164,24 @@ module Sidekiq
163
164
  end
164
165
 
165
166
  def root_path
166
- "#{env['SCRIPT_NAME']}/"
167
+ "#{env["SCRIPT_NAME"]}/"
167
168
  end
168
169
 
169
170
  def current_path
170
- @current_path ||= request.path_info.gsub(/^\//,'')
171
+ @current_path ||= request.path_info.gsub(/^\//, "")
171
172
  end
172
173
 
173
174
  def current_status
174
- workers.size == 0 ? 'idle' : 'active'
175
+ workers.size == 0 ? "idle" : "active"
175
176
  end
176
177
 
177
178
  def relative_time(time)
178
179
  stamp = time.getutc.iso8601
179
- %{<time class="ltr" dir="ltr" title="#{stamp}" datetime="#{stamp}">#{time}</time>}
180
+ %(<time class="ltr" dir="ltr" title="#{stamp}" datetime="#{stamp}">#{time}</time>)
180
181
  end
181
182
 
182
183
  def job_params(job, score)
183
- "#{score}-#{job['jid']}"
184
+ "#{score}-#{job["jid"]}"
184
185
  end
185
186
 
186
187
  def parse_params(params)
@@ -188,7 +189,7 @@ module Sidekiq
188
189
  [score.to_f, jid]
189
190
  end
190
191
 
191
- SAFE_QPARAMS = %w(page poll)
192
+ SAFE_QPARAMS = %w[page poll]
192
193
 
193
194
  # Merge options with current params, filter safe params, and stringify to query string
194
195
  def qparams(options)
@@ -197,9 +198,9 @@ module Sidekiq
197
198
  options[key.to_s] = options.delete(key)
198
199
  end
199
200
 
200
- params.merge(options).map do |key, value|
201
+ params.merge(options).map { |key, value|
201
202
  SAFE_QPARAMS.include?(key) ? "#{key}=#{CGI.escape(value.to_s)}" : next
202
- end.compact.join("&")
203
+ }.compact.join("&")
203
204
  end
204
205
 
205
206
  def truncate(text, truncate_after_chars = 2000)
@@ -207,13 +208,13 @@ module Sidekiq
207
208
  end
208
209
 
209
210
  def display_args(args, truncate_after_chars = 2000)
210
- return "Invalid job payload, args is nil" if args == nil
211
- return "Invalid job payload, args must be an Array, not #{args.class.name}" if !args.is_a?(Array)
211
+ return "Invalid job payload, args is nil" if args.nil?
212
+ return "Invalid job payload, args must be an Array, not #{args.class.name}" unless args.is_a?(Array)
212
213
 
213
214
  begin
214
- args.map do |arg|
215
+ args.map { |arg|
215
216
  h(truncate(to_display(arg), truncate_after_chars))
216
- end.join(", ")
217
+ }.join(", ")
217
218
  rescue
218
219
  "Illegal job arguments: #{h args.inspect}"
219
220
  end
@@ -224,23 +225,21 @@ module Sidekiq
224
225
  end
225
226
 
226
227
  def to_display(arg)
228
+ arg.inspect
229
+ rescue
227
230
  begin
228
- arg.inspect
229
- rescue
230
- begin
231
- arg.to_s
232
- rescue => ex
233
- "Cannot display argument: [#{ex.class.name}] #{ex.message}"
234
- end
231
+ arg.to_s
232
+ rescue => ex
233
+ "Cannot display argument: [#{ex.class.name}] #{ex.message}"
235
234
  end
236
235
  end
237
236
 
238
- RETRY_JOB_KEYS = Set.new(%w(
237
+ RETRY_JOB_KEYS = Set.new(%w[
239
238
  queue class args retry_count retried_at failed_at
240
239
  jid error_message error_class backtrace
241
240
  error_backtrace enqueued_at retry wrapped
242
241
  created_at
243
- ))
242
+ ])
244
243
 
245
244
  def retry_extra_items(retry_job)
246
245
  @retry_extra_items ||= {}.tap do |extra|
@@ -257,8 +256,8 @@ module Sidekiq
257
256
  return number
258
257
  end
259
258
 
260
- options = {delimiter: ',', separator: '.'}
261
- parts = number.to_s.to_str.split('.')
259
+ options = {delimiter: ",", separator: "."}
260
+ parts = number.to_s.to_str.split(".")
262
261
  parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{options[:delimiter]}")
263
262
  parts.join(options[:separator])
264
263
  end
@@ -266,8 +265,8 @@ module Sidekiq
266
265
  def h(text)
267
266
  ::Rack::Utils.escape_html(text)
268
267
  rescue ArgumentError => e
269
- raise unless e.message.eql?('invalid byte sequence in UTF-8')
270
- text.encode!('UTF-16', 'UTF-8', invalid: :replace, replace: '').encode!('UTF-8', 'UTF-16')
268
+ raise unless e.message.eql?("invalid byte sequence in UTF-8")
269
+ text.encode!("UTF-16", "UTF-8", invalid: :replace, replace: "").encode!("UTF-8", "UTF-16")
271
270
  retry
272
271
  end
273
272
 
@@ -284,7 +283,7 @@ module Sidekiq
284
283
  end
285
284
 
286
285
  def environment_title_prefix
287
- environment = Sidekiq.options[:environment] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
286
+ environment = Sidekiq.options[:environment] || ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
288
287
 
289
288
  "[#{environment.upcase}] " unless environment == "production"
290
289
  end
@@ -294,30 +293,30 @@ module Sidekiq
294
293
  end
295
294
 
296
295
  def server_utc_time
297
- Time.now.utc.strftime('%H:%M:%S UTC')
296
+ Time.now.utc.strftime("%H:%M:%S UTC")
298
297
  end
299
298
 
300
299
  def redis_connection_and_namespace
301
300
  @redis_connection_and_namespace ||= begin
302
- namespace_suffix = namespace == nil ? '' : "##{namespace}"
301
+ namespace_suffix = namespace.nil? ? "" : "##{namespace}"
303
302
  "#{redis_connection}#{namespace_suffix}"
304
303
  end
305
304
  end
306
305
 
307
306
  def retry_or_delete_or_kill(job, params)
308
- if params['retry']
307
+ if params["retry"]
309
308
  job.retry
310
- elsif params['delete']
309
+ elsif params["delete"]
311
310
  job.delete
312
- elsif params['kill']
311
+ elsif params["kill"]
313
312
  job.kill
314
313
  end
315
314
  end
316
315
 
317
316
  def delete_or_add_queue(job, params)
318
- if params['delete']
317
+ if params["delete"]
319
318
  job.delete
320
- elsif params['add_to_queue']
319
+ elsif params["add_to_queue"]
321
320
  job.add_to_queue
322
321
  end
323
322
  end