sidekiq 5.2.9 → 6.1.2

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 (89) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +20 -0
  3. data/.github/workflows/ci.yml +41 -0
  4. data/.gitignore +0 -2
  5. data/.standard.yml +20 -0
  6. data/6.0-Upgrade.md +72 -0
  7. data/Changes.md +184 -0
  8. data/Ent-2.0-Upgrade.md +37 -0
  9. data/Ent-Changes.md +44 -1
  10. data/Gemfile +12 -11
  11. data/Gemfile.lock +192 -0
  12. data/Pro-5.0-Upgrade.md +25 -0
  13. data/Pro-Changes.md +48 -2
  14. data/README.md +18 -34
  15. data/Rakefile +5 -4
  16. data/bin/sidekiq +26 -2
  17. data/bin/sidekiqload +32 -24
  18. data/bin/sidekiqmon +8 -0
  19. data/lib/generators/sidekiq/templates/worker_test.rb.erb +1 -1
  20. data/lib/generators/sidekiq/worker_generator.rb +21 -13
  21. data/lib/sidekiq/api.rb +242 -219
  22. data/lib/sidekiq/cli.rb +131 -180
  23. data/lib/sidekiq/client.rb +67 -47
  24. data/lib/sidekiq/delay.rb +5 -6
  25. data/lib/sidekiq/exception_handler.rb +10 -12
  26. data/lib/sidekiq/extensions/action_mailer.rb +13 -22
  27. data/lib/sidekiq/extensions/active_record.rb +13 -10
  28. data/lib/sidekiq/extensions/class_methods.rb +14 -11
  29. data/lib/sidekiq/extensions/generic_proxy.rb +4 -4
  30. data/lib/sidekiq/fetch.rb +29 -30
  31. data/lib/sidekiq/job_logger.rb +45 -7
  32. data/lib/sidekiq/job_retry.rb +61 -61
  33. data/lib/sidekiq/launcher.rb +88 -55
  34. data/lib/sidekiq/logger.rb +165 -0
  35. data/lib/sidekiq/manager.rb +11 -13
  36. data/lib/sidekiq/middleware/chain.rb +15 -5
  37. data/lib/sidekiq/middleware/i18n.rb +5 -7
  38. data/lib/sidekiq/monitor.rb +133 -0
  39. data/lib/sidekiq/paginator.rb +18 -14
  40. data/lib/sidekiq/processor.rb +71 -70
  41. data/lib/sidekiq/rails.rb +29 -37
  42. data/lib/sidekiq/redis_connection.rb +50 -48
  43. data/lib/sidekiq/scheduled.rb +28 -29
  44. data/lib/sidekiq/sd_notify.rb +149 -0
  45. data/lib/sidekiq/systemd.rb +24 -0
  46. data/lib/sidekiq/testing/inline.rb +2 -1
  47. data/lib/sidekiq/testing.rb +35 -24
  48. data/lib/sidekiq/util.rb +17 -16
  49. data/lib/sidekiq/version.rb +2 -1
  50. data/lib/sidekiq/web/action.rb +14 -10
  51. data/lib/sidekiq/web/application.rb +73 -71
  52. data/lib/sidekiq/web/csrf_protection.rb +158 -0
  53. data/lib/sidekiq/web/helpers.rb +85 -77
  54. data/lib/sidekiq/web/router.rb +18 -17
  55. data/lib/sidekiq/web.rb +53 -53
  56. data/lib/sidekiq/worker.rb +126 -102
  57. data/lib/sidekiq.rb +69 -44
  58. data/sidekiq.gemspec +15 -16
  59. data/web/assets/javascripts/application.js +25 -27
  60. data/web/assets/javascripts/dashboard.js +4 -23
  61. data/web/assets/stylesheets/application-dark.css +143 -0
  62. data/web/assets/stylesheets/application.css +16 -6
  63. data/web/locales/de.yml +14 -2
  64. data/web/locales/en.yml +2 -0
  65. data/web/locales/fr.yml +2 -2
  66. data/web/locales/ja.yml +4 -1
  67. data/web/locales/lt.yml +83 -0
  68. data/web/locales/pl.yml +4 -4
  69. data/web/locales/ru.yml +4 -0
  70. data/web/locales/vi.yml +83 -0
  71. data/web/views/_job_info.erb +2 -1
  72. data/web/views/busy.erb +6 -3
  73. data/web/views/dead.erb +2 -2
  74. data/web/views/layout.erb +1 -0
  75. data/web/views/morgue.erb +5 -2
  76. data/web/views/queue.erb +10 -1
  77. data/web/views/queues.erb +9 -1
  78. data/web/views/retries.erb +5 -2
  79. data/web/views/retry.erb +2 -2
  80. data/web/views/scheduled.erb +5 -2
  81. metadata +25 -43
  82. data/.circleci/config.yml +0 -61
  83. data/.github/issue_template.md +0 -11
  84. data/.travis.yml +0 -11
  85. data/bin/sidekiqctl +0 -20
  86. data/lib/sidekiq/core_ext.rb +0 -1
  87. data/lib/sidekiq/ctl.rb +0 -221
  88. data/lib/sidekiq/logging.rb +0 -122
  89. data/lib/sidekiq/middleware/server/active_record.rb +0 -23
data/lib/sidekiq/cli.rb CHANGED
@@ -1,29 +1,22 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  $stdout.sync = true
3
4
 
4
- require 'yaml'
5
- require 'singleton'
6
- require 'optparse'
7
- require 'erb'
8
- require 'fileutils'
5
+ require "yaml"
6
+ require "singleton"
7
+ require "optparse"
8
+ require "erb"
9
+ require "fileutils"
9
10
 
10
- require 'sidekiq'
11
- require 'sidekiq/util'
12
- require 'sidekiq/launcher'
11
+ require "sidekiq"
12
+ require "sidekiq/launcher"
13
+ require "sidekiq/util"
13
14
 
14
15
  module Sidekiq
15
16
  class CLI
16
17
  include Util
17
18
  include Singleton unless $TESTING
18
19
 
19
- PROCTITLES = [
20
- proc { 'sidekiq' },
21
- proc { Sidekiq::VERSION },
22
- proc { |me, data| data['tag'] },
23
- proc { |me, data| "[#{Processor::WORKER_STATE.size} of #{data['concurrency']} busy]" },
24
- proc { |me, data| "stopping" if me.stopping? },
25
- ]
26
-
27
20
  attr_accessor :launcher
28
21
  attr_accessor :environment
29
22
 
@@ -40,39 +33,34 @@ module Sidekiq
40
33
  # Code within this method is not tested because it alters
41
34
  # global process state irreversibly. PRs which improve the
42
35
  # test coverage of Sidekiq::CLI are welcomed.
43
- def run
44
- daemonize if options[:daemon]
45
- write_pid
46
- boot_system
47
- print_banner if environment == 'development' && $stdout.tty?
36
+ def run(boot_app: true)
37
+ boot_application if boot_app
48
38
 
49
- self_read, self_write = IO.pipe
50
- sigs = %w(INT TERM TTIN TSTP)
51
- # USR1 and USR2 don't work on the JVM
52
- if !jruby?
53
- sigs << 'USR1'
54
- sigs << 'USR2'
39
+ if environment == "development" && $stdout.tty? && Sidekiq.log_formatter.is_a?(Sidekiq::Logger::Formatters::Pretty)
40
+ print_banner
55
41
  end
42
+ logger.info "Booted Rails #{::Rails.version} application in #{environment} environment" if rails_app?
56
43
 
44
+ self_read, self_write = IO.pipe
45
+ sigs = %w[INT TERM TTIN TSTP]
46
+ # USR1 and USR2 don't work on the JVM
47
+ sigs << "USR2" if Sidekiq.pro? && !jruby?
57
48
  sigs.each do |sig|
58
- begin
59
- trap sig do
60
- self_write.write("#{sig}\n")
61
- end
62
- rescue ArgumentError
63
- puts "Signal #{sig} not supported"
49
+ trap sig do
50
+ self_write.puts(sig)
64
51
  end
52
+ rescue ArgumentError
53
+ puts "Signal #{sig} not supported"
65
54
  end
66
55
 
67
56
  logger.info "Running in #{RUBY_DESCRIPTION}"
68
57
  logger.info Sidekiq::LICENSE
69
- logger.info "Upgrade to Sidekiq Pro for more features and support: http://sidekiq.org" unless defined?(::Sidekiq::Pro)
58
+ logger.info "Upgrade to Sidekiq Pro for more features and support: https://sidekiq.org" unless defined?(::Sidekiq::Pro)
70
59
 
71
60
  # touch the connection pool so it is created before we
72
61
  # fire startup and start multithreading.
73
- ver = Sidekiq.redis_info['redis_version']
74
- raise "You are using Redis v#{ver}, Sidekiq requires Redis v2.8.0 or greater" if ver < '2.8'
75
- logger.warn "Sidekiq 6.0 will require Redis 4.0+, you are using Redis v#{ver}" if ver < '4'
62
+ ver = Sidekiq.redis_info["redis_version"]
63
+ raise "You are connecting to Redis v#{ver}, Sidekiq requires Redis v4.0.0 or greater" if ver < "4"
76
64
 
77
65
  # Since the user can pass us a connection pool explicitly in the initializer, we
78
66
  # need to verify the size is large enough or else Sidekiq's performance is dramatically slowed.
@@ -90,15 +78,15 @@ module Sidekiq
90
78
  # Starting here the process will now have multiple threads running.
91
79
  fire_event(:startup, reverse: false, reraise: true)
92
80
 
93
- logger.debug { "Client Middleware: #{Sidekiq.client_middleware.map(&:klass).join(', ')}" }
94
- logger.debug { "Server Middleware: #{Sidekiq.server_middleware.map(&:klass).join(', ')}" }
81
+ logger.debug { "Client Middleware: #{Sidekiq.client_middleware.map(&:klass).join(", ")}" }
82
+ logger.debug { "Server Middleware: #{Sidekiq.server_middleware.map(&:klass).join(", ")}" }
95
83
 
96
84
  launch(self_read)
97
85
  end
98
86
 
99
87
  def launch(self_read)
100
- if !options[:daemon]
101
- logger.info 'Starting processing, hit Ctrl-C to stop'
88
+ if environment == "development" && $stdout.tty?
89
+ logger.info "Starting processing, hit Ctrl-C to stop"
102
90
  end
103
91
 
104
92
  @launcher = Sidekiq::Launcher.new(options)
@@ -106,121 +94,107 @@ module Sidekiq
106
94
  begin
107
95
  launcher.run
108
96
 
109
- while readable_io = IO.select([self_read])
97
+ while (readable_io = IO.select([self_read]))
110
98
  signal = readable_io.first[0].gets.strip
111
99
  handle_signal(signal)
112
100
  end
113
101
  rescue Interrupt
114
- logger.info 'Shutting down'
102
+ logger.info "Shutting down"
115
103
  launcher.stop
116
- # Explicitly exit so busy Processor threads can't block
117
- # process shutdown.
118
104
  logger.info "Bye!"
105
+
106
+ # Explicitly exit so busy Processor threads won't block process shutdown.
107
+ #
108
+ # NB: slow at_exit handlers will prevent a timely exit if they take
109
+ # a while to run. If Sidekiq is getting here but the process isn't exiting,
110
+ # use the TTIN signal to determine where things are stuck.
119
111
  exit(0)
120
112
  end
121
113
  end
122
114
 
115
+ def self.w
116
+ "\e[37m"
117
+ end
118
+
119
+ def self.r
120
+ "\e[31m"
121
+ end
122
+
123
+ def self.b
124
+ "\e[30m"
125
+ end
126
+
127
+ def self.reset
128
+ "\e[0m"
129
+ end
130
+
123
131
  def self.banner
124
- %q{
125
- m,
126
- `$b
127
- .ss, $$: .,d$
128
- `$$P,d$P' .,md$P"'
129
- ,$$$$$bmmd$$$P^'
130
- .d$$$$$$$$$$P'
131
- $$^' `"^$$$' ____ _ _ _ _
132
- $: ,$$: / ___|(_) __| | ___| | _(_) __ _
133
- `b :$$ \___ \| |/ _` |/ _ \ |/ / |/ _` |
134
- $$: ___) | | (_| | __/ <| | (_| |
135
- $$ |____/|_|\__,_|\___|_|\_\_|\__, |
136
- .d$$ |_|
137
- }
132
+ %{
133
+ #{w} m,
134
+ #{w} `$b
135
+ #{w} .ss, $$: .,d$
136
+ #{w} `$$P,d$P' .,md$P"'
137
+ #{w} ,$$$$$b#{b}/#{w}md$$$P^'
138
+ #{w} .d$$$$$$#{b}/#{w}$$$P'
139
+ #{w} $$^' `"#{b}/#{w}$$$' #{r}____ _ _ _ _
140
+ #{w} $: ,$$: #{r} / ___|(_) __| | ___| | _(_) __ _
141
+ #{w} `b :$$ #{r} \\___ \\| |/ _` |/ _ \\ |/ / |/ _` |
142
+ #{w} $$: #{r} ___) | | (_| | __/ <| | (_| |
143
+ #{w} $$ #{r}|____/|_|\\__,_|\\___|_|\\_\\_|\\__, |
144
+ #{w} .d$$ #{r} |_|
145
+ #{reset}}
138
146
  end
139
147
 
140
148
  SIGNAL_HANDLERS = {
141
149
  # Ctrl-C in terminal
142
- 'INT' => ->(cli) { raise Interrupt },
150
+ "INT" => ->(cli) { raise Interrupt },
143
151
  # TERM is the signal that Sidekiq must exit.
144
152
  # Heroku sends TERM and then waits 30 seconds for process to exit.
145
- 'TERM' => ->(cli) { raise Interrupt },
146
- 'USR1' => ->(cli) {
147
- Sidekiq.logger.info "Received USR1, no longer accepting new work"
148
- cli.launcher.quiet
149
- },
150
- 'TSTP' => ->(cli) {
153
+ "TERM" => ->(cli) { raise Interrupt },
154
+ "TSTP" => ->(cli) {
151
155
  Sidekiq.logger.info "Received TSTP, no longer accepting new work"
152
156
  cli.launcher.quiet
153
157
  },
154
- 'USR2' => ->(cli) {
155
- if Sidekiq.options[:logfile]
156
- Sidekiq.logger.info "Received USR2, reopening log file"
157
- Sidekiq::Logging.reopen_logs
158
- end
159
- },
160
- 'TTIN' => ->(cli) {
158
+ "TTIN" => ->(cli) {
161
159
  Thread.list.each do |thread|
162
- Sidekiq.logger.warn "Thread TID-#{(thread.object_id ^ ::Process.pid).to_s(36)} #{thread['sidekiq_label']}"
160
+ Sidekiq.logger.warn "Thread TID-#{(thread.object_id ^ ::Process.pid).to_s(36)} #{thread.name}"
163
161
  if thread.backtrace
164
162
  Sidekiq.logger.warn thread.backtrace.join("\n")
165
163
  else
166
164
  Sidekiq.logger.warn "<no backtrace available>"
167
165
  end
168
166
  end
169
- },
167
+ }
170
168
  }
169
+ UNHANDLED_SIGNAL_HANDLER = ->(cli) { Sidekiq.logger.info "No signal handler registered, ignoring" }
170
+ SIGNAL_HANDLERS.default = UNHANDLED_SIGNAL_HANDLER
171
171
 
172
172
  def handle_signal(sig)
173
173
  Sidekiq.logger.debug "Got #{sig} signal"
174
- handy = SIGNAL_HANDLERS[sig]
175
- if handy
176
- handy.call(self)
177
- else
178
- Sidekiq.logger.info { "No signal handler for #{sig}" }
179
- end
174
+ SIGNAL_HANDLERS[sig].call(self)
180
175
  end
181
176
 
182
177
  private
183
178
 
184
179
  def print_banner
185
- puts "\e[#{31}m"
180
+ puts "\e[31m"
186
181
  puts Sidekiq::CLI.banner
187
182
  puts "\e[0m"
188
183
  end
189
184
 
190
- def daemonize
191
- raise ArgumentError, "You really should set a logfile if you're going to daemonize" unless options[:logfile]
192
-
193
- files_to_reopen = ObjectSpace.each_object(File).reject { |f| f.closed? }
194
- ::Process.daemon(true, true)
195
-
196
- files_to_reopen.each do |file|
197
- begin
198
- file.reopen file.path, "a+"
199
- file.sync = true
200
- rescue ::Exception
201
- end
202
- end
203
-
204
- [$stdout, $stderr].each do |io|
205
- File.open(options[:logfile], 'ab') do |f|
206
- io.reopen(f)
207
- end
208
- io.sync = true
209
- end
210
- $stdin.reopen('/dev/null')
211
-
212
- initialize_logger
213
- end
214
-
215
185
  def set_environment(cli_env)
216
- @environment = cli_env || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
186
+ # See #984 for discussion.
187
+ # APP_ENV is now the preferred ENV term since it is not tech-specific.
188
+ # Both Sinatra 2.0+ and Sidekiq support this term.
189
+ # RAILS_ENV and RACK_ENV are there for legacy support.
190
+ @environment = cli_env || ENV["APP_ENV"] || ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
217
191
  end
218
192
 
219
193
  def symbolize_keys_deep!(hash)
220
194
  hash.keys.each do |k|
221
195
  symkey = k.respond_to?(:to_sym) ? k.to_sym : k
222
196
  hash[symkey] = hash.delete k
223
- symbolize_keys_deep! hash[symkey] if hash[symkey].kind_of? Hash
197
+ symbolize_keys_deep! hash[symkey] if hash[symkey].is_a? Hash
224
198
  end
225
199
  end
226
200
 
@@ -235,14 +209,14 @@ module Sidekiq
235
209
 
236
210
  # check config file presence
237
211
  if opts[:config_file]
238
- if opts[:config_file] && !File.exist?(opts[:config_file])
212
+ unless File.exist?(opts[:config_file])
239
213
  raise ArgumentError, "No such file #{opts[:config_file]}"
240
214
  end
241
215
  else
242
216
  config_dir = if File.directory?(opts[:require].to_s)
243
- File.join(opts[:require], 'config')
217
+ File.join(opts[:require], "config")
244
218
  else
245
- File.join(options[:require], 'config')
219
+ File.join(options[:require], "config")
246
220
  end
247
221
 
248
222
  %w[sidekiq.yml sidekiq.yml.erb].each do |config_file|
@@ -255,8 +229,7 @@ module Sidekiq
255
229
  opts = parse_config(opts[:config_file]).merge(opts) if opts[:config_file]
256
230
 
257
231
  # set defaults
258
- opts[:queues] = Array(opts[:queues]) << 'default' if opts[:queues].nil? || opts[:queues].empty?
259
- opts[:strict] = true if opts[:strict].nil?
232
+ opts[:queues] = ["default"] if opts[:queues].nil?
260
233
  opts[:concurrency] = Integer(ENV["RAILS_MAX_THREADS"]) if opts[:concurrency].nil? && ENV["RAILS_MAX_THREADS"]
261
234
 
262
235
  # merge with defaults
@@ -267,24 +240,15 @@ module Sidekiq
267
240
  Sidekiq.options
268
241
  end
269
242
 
270
- def boot_system
271
- ENV['RACK_ENV'] = ENV['RAILS_ENV'] = environment
243
+ def boot_application
244
+ ENV["RACK_ENV"] = ENV["RAILS_ENV"] = environment
272
245
 
273
246
  if File.directory?(options[:require])
274
- require 'rails'
275
- if ::Rails::VERSION::MAJOR < 4
247
+ require "rails"
248
+ if ::Rails::VERSION::MAJOR < 5
276
249
  raise "Sidekiq no longer supports this version of Rails"
277
- elsif ::Rails::VERSION::MAJOR == 4
278
- # Painful contortions, see 1791 for discussion
279
- # No autoloading, we want to force eager load for everything.
280
- require File.expand_path("#{options[:require]}/config/application.rb")
281
- ::Rails::Application.initializer "sidekiq.eager_load" do
282
- ::Rails.application.config.eager_load = true
283
- end
284
- require 'sidekiq/rails'
285
- require File.expand_path("#{options[:require]}/config/environment.rb")
286
250
  else
287
- require 'sidekiq/rails'
251
+ require "sidekiq/rails"
288
252
  require File.expand_path("#{options[:require]}/config/environment.rb")
289
253
  end
290
254
  options[:tag] ||= default_tag
@@ -296,8 +260,9 @@ module Sidekiq
296
260
  def default_tag
297
261
  dir = ::Rails.root
298
262
  name = File.basename(dir)
299
- if name.to_i != 0 && prevdir = File.dirname(dir) # Capistrano release directory?
300
- if File.basename(prevdir) == 'releases'
263
+ prevdir = File.dirname(dir) # Capistrano release directory?
264
+ if name.to_i != 0 && prevdir
265
+ if File.basename(prevdir) == "releases"
301
266
  return File.basename(File.dirname(prevdir))
302
267
  end
303
268
  end
@@ -306,9 +271,9 @@ module Sidekiq
306
271
 
307
272
  def validate!
308
273
  if !File.exist?(options[:require]) ||
309
- (File.directory?(options[:require]) && !File.exist?("#{options[:require]}/config/application.rb"))
274
+ (File.directory?(options[:require]) && !File.exist?("#{options[:require]}/config/application.rb"))
310
275
  logger.info "=================================================================="
311
- logger.info " Please point sidekiq to a Rails 4/5 application or a Ruby file "
276
+ logger.info " Please point Sidekiq to a Rails application or a Ruby file "
312
277
  logger.info " to load your worker classes with -r [DIR|FILE]."
313
278
  logger.info "=================================================================="
314
279
  logger.info @parser
@@ -316,47 +281,45 @@ module Sidekiq
316
281
  end
317
282
 
318
283
  [:concurrency, :timeout].each do |opt|
319
- raise ArgumentError, "#{opt}: #{options[opt]} is not a valid value" if options.has_key?(opt) && options[opt].to_i <= 0
284
+ raise ArgumentError, "#{opt}: #{options[opt]} is not a valid value" if options.key?(opt) && options[opt].to_i <= 0
320
285
  end
321
286
  end
322
287
 
323
288
  def parse_options(argv)
324
289
  opts = {}
290
+ @parser = option_parser(opts)
291
+ @parser.parse!(argv)
292
+ opts
293
+ end
325
294
 
326
- @parser = OptionParser.new do |o|
327
- o.on '-c', '--concurrency INT', "processor threads to use" do |arg|
295
+ def option_parser(opts)
296
+ parser = OptionParser.new { |o|
297
+ o.on "-c", "--concurrency INT", "processor threads to use" do |arg|
328
298
  opts[:concurrency] = Integer(arg)
329
299
  end
330
300
 
331
- o.on '-d', '--daemon', "Daemonize process" do |arg|
332
- opts[:daemon] = arg
333
- puts "WARNING: Daemonization mode will be removed in Sidekiq 6.0, see #4045. Please use a proper process supervisor to start and manage your services"
301
+ o.on "-d", "--daemon", "Daemonize process" do |arg|
302
+ puts "ERROR: Daemonization mode was removed in Sidekiq 6.0, please use a proper process supervisor to start and manage your services"
334
303
  end
335
304
 
336
- o.on '-e', '--environment ENV', "Application environment" do |arg|
305
+ o.on "-e", "--environment ENV", "Application environment" do |arg|
337
306
  opts[:environment] = arg
338
307
  end
339
308
 
340
- o.on '-g', '--tag TAG', "Process tag for procline" do |arg|
309
+ o.on "-g", "--tag TAG", "Process tag for procline" do |arg|
341
310
  opts[:tag] = arg
342
311
  end
343
312
 
344
- # this index remains here for backwards compatibility but none of the Sidekiq
345
- # family use this value anymore. it was used by Pro's original reliable_fetch.
346
- o.on '-i', '--index INT', "unique process index on this machine" do |arg|
347
- opts[:index] = Integer(arg.match(/\d+/)[0])
348
- end
349
-
350
313
  o.on "-q", "--queue QUEUE[,WEIGHT]", "Queues to process with optional weights" do |arg|
351
314
  queue, weight = arg.split(",")
352
315
  parse_queue opts, queue, weight
353
316
  end
354
317
 
355
- o.on '-r', '--require [PATH|DIR]', "Location of Rails application with workers or file to require" do |arg|
318
+ o.on "-r", "--require [PATH|DIR]", "Location of Rails application with workers or file to require" do |arg|
356
319
  opts[:require] = arg
357
320
  end
358
321
 
359
- o.on '-t', '--timeout NUM', "Shutdown timeout" do |arg|
322
+ o.on "-t", "--timeout NUM", "Shutdown timeout" do |arg|
360
323
  opts[:timeout] = Integer(arg)
361
324
  end
362
325
 
@@ -364,52 +327,37 @@ module Sidekiq
364
327
  opts[:verbose] = arg
365
328
  end
366
329
 
367
- o.on '-C', '--config PATH', "path to YAML config file" do |arg|
330
+ o.on "-C", "--config PATH", "path to YAML config file" do |arg|
368
331
  opts[:config_file] = arg
369
332
  end
370
333
 
371
- o.on '-L', '--logfile PATH', "path to writable logfile" do |arg|
372
- opts[:logfile] = arg
373
- puts "WARNING: Logfile redirection will be removed in Sidekiq 6.0, see #4045. Sidekiq will only log to STDOUT"
334
+ o.on "-L", "--logfile PATH", "path to writable logfile" do |arg|
335
+ puts "ERROR: Logfile redirection was removed in Sidekiq 6.0, Sidekiq will only log to STDOUT"
374
336
  end
375
337
 
376
- o.on '-P', '--pidfile PATH', "path to pidfile" do |arg|
377
- opts[:pidfile] = arg
378
- puts "WARNING: PID file creation will be removed in Sidekiq 6.0, see #4045. Please use a proper process supervisor to start and manage your services"
338
+ o.on "-P", "--pidfile PATH", "path to pidfile" do |arg|
339
+ puts "ERROR: PID file creation was removed in Sidekiq 6.0, please use a proper process supervisor to start and manage your services"
379
340
  end
380
341
 
381
- o.on '-V', '--version', "Print version and exit" do |arg|
342
+ o.on "-V", "--version", "Print version and exit" do |arg|
382
343
  puts "Sidekiq #{Sidekiq::VERSION}"
383
344
  die(0)
384
345
  end
385
- end
346
+ }
386
347
 
387
- @parser.banner = "sidekiq [options]"
388
- @parser.on_tail "-h", "--help", "Show help" do
389
- logger.info @parser
348
+ parser.banner = "sidekiq [options]"
349
+ parser.on_tail "-h", "--help", "Show help" do
350
+ logger.info parser
390
351
  die 1
391
352
  end
392
353
 
393
- @parser.parse!(argv)
394
-
395
- opts
354
+ parser
396
355
  end
397
356
 
398
357
  def initialize_logger
399
- Sidekiq::Logging.initialize_logger(options[:logfile]) if options[:logfile]
400
-
401
358
  Sidekiq.logger.level = ::Logger::DEBUG if options[:verbose]
402
359
  end
403
360
 
404
- def write_pid
405
- if path = options[:pidfile]
406
- pidfile = File.expand_path(path)
407
- File.open(pidfile, 'w') do |f|
408
- f.puts ::Process.pid
409
- end
410
- end
411
- end
412
-
413
361
  def parse_config(path)
414
362
  opts = YAML.load(ERB.new(File.read(path)).result) || {}
415
363
 
@@ -420,14 +368,10 @@ module Sidekiq
420
368
  end
421
369
 
422
370
  opts = opts.merge(opts.delete(environment.to_sym) || {})
371
+ opts.delete(:strict)
372
+
423
373
  parse_queues(opts, opts.delete(:queues) || [])
424
374
 
425
- ns = opts.delete(:namespace)
426
- if ns
427
- # logger hasn't been initialized yet, puts is all we have.
428
- puts("namespace should be set in your ruby initializer, is ignored in config file")
429
- puts("config.redis = { :url => ..., :namespace => '#{ns}' }")
430
- end
431
375
  opts
432
376
  end
433
377
 
@@ -437,9 +381,16 @@ module Sidekiq
437
381
 
438
382
  def parse_queue(opts, queue, weight = nil)
439
383
  opts[:queues] ||= []
384
+ opts[:strict] = true if opts[:strict].nil?
440
385
  raise ArgumentError, "queues: #{queue} cannot be defined twice" if opts[:queues].include?(queue)
441
386
  [weight.to_i, 1].max.times { opts[:queues] << queue }
442
387
  opts[:strict] = false if weight.to_i > 0
443
388
  end
389
+
390
+ def rails_app?
391
+ defined?(::Rails) && ::Rails.respond_to?(:application)
392
+ end
444
393
  end
445
394
  end
395
+
396
+ require "sidekiq/systemd"