sidekiq 5.2.8 → 6.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of sidekiq might be problematic. Click here for more details.
- checksums.yaml +4 -4
 - data/.github/ISSUE_TEMPLATE/bug_report.md +20 -0
 - data/.github/workflows/ci.yml +41 -0
 - data/.gitignore +0 -2
 - data/.standard.yml +20 -0
 - data/5.0-Upgrade.md +1 -1
 - data/6.0-Upgrade.md +72 -0
 - data/Changes.md +196 -0
 - data/Ent-2.0-Upgrade.md +37 -0
 - data/Ent-Changes.md +72 -1
 - data/Gemfile +12 -11
 - data/Gemfile.lock +193 -0
 - data/Pro-5.0-Upgrade.md +25 -0
 - data/Pro-Changes.md +56 -2
 - data/README.md +18 -34
 - data/Rakefile +5 -4
 - data/bin/sidekiq +26 -2
 - data/bin/sidekiqload +32 -24
 - data/bin/sidekiqmon +8 -0
 - data/lib/generators/sidekiq/templates/worker_test.rb.erb +1 -1
 - data/lib/generators/sidekiq/worker_generator.rb +21 -13
 - data/lib/sidekiq/api.rb +245 -219
 - data/lib/sidekiq/cli.rb +144 -180
 - data/lib/sidekiq/client.rb +68 -48
 - data/lib/sidekiq/delay.rb +5 -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 +4 -4
 - data/lib/sidekiq/fetch.rb +29 -30
 - data/lib/sidekiq/job_logger.rb +45 -7
 - data/lib/sidekiq/job_retry.rb +62 -61
 - data/lib/sidekiq/launcher.rb +112 -54
 - data/lib/sidekiq/logger.rb +166 -0
 - data/lib/sidekiq/manager.rb +11 -13
 - data/lib/sidekiq/middleware/chain.rb +15 -5
 - data/lib/sidekiq/middleware/i18n.rb +5 -7
 - data/lib/sidekiq/monitor.rb +133 -0
 - data/lib/sidekiq/paginator.rb +18 -14
 - data/lib/sidekiq/processor.rb +71 -70
 - data/lib/sidekiq/rails.rb +29 -37
 - data/lib/sidekiq/redis_connection.rb +50 -48
 - data/lib/sidekiq/scheduled.rb +28 -29
 - 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 +35 -24
 - data/lib/sidekiq/util.rb +17 -16
 - data/lib/sidekiq/version.rb +2 -1
 - data/lib/sidekiq/web/action.rb +14 -10
 - data/lib/sidekiq/web/application.rb +74 -72
 - data/lib/sidekiq/web/csrf_protection.rb +156 -0
 - data/lib/sidekiq/web/helpers.rb +97 -77
 - data/lib/sidekiq/web/router.rb +18 -17
 - data/lib/sidekiq/web.rb +53 -53
 - data/lib/sidekiq/worker.rb +126 -102
 - data/lib/sidekiq.rb +69 -44
 - data/sidekiq.gemspec +15 -16
 - data/web/assets/javascripts/application.js +25 -27
 - data/web/assets/javascripts/dashboard.js +4 -23
 - data/web/assets/stylesheets/application-dark.css +149 -0
 - data/web/assets/stylesheets/application.css +28 -6
 - data/web/locales/de.yml +14 -2
 - data/web/locales/en.yml +2 -0
 - data/web/locales/fr.yml +3 -3
 - data/web/locales/ja.yml +4 -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/_job_info.erb +2 -1
 - data/web/views/busy.erb +8 -3
 - data/web/views/dead.erb +2 -2
 - data/web/views/layout.erb +1 -0
 - data/web/views/morgue.erb +5 -2
 - data/web/views/queue.erb +10 -1
 - data/web/views/queues.erb +9 -1
 - data/web/views/retries.erb +5 -2
 - data/web/views/retry.erb +2 -2
 - data/web/views/scheduled.erb +5 -2
 - metadata +31 -49
 - data/.circleci/config.yml +0 -61
 - data/.github/issue_template.md +0 -11
 - data/.travis.yml +0 -11
 - data/bin/sidekiqctl +0 -20
 - 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
 
    
        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  
     | 
| 
       5 
     | 
    
         
            -
            require  
     | 
| 
       6 
     | 
    
         
            -
            require  
     | 
| 
       7 
     | 
    
         
            -
            require  
     | 
| 
       8 
     | 
    
         
            -
            require  
     | 
| 
      
 5 
     | 
    
         
            +
            require "yaml"
         
     | 
| 
      
 6 
     | 
    
         
            +
            require "singleton"
         
     | 
| 
      
 7 
     | 
    
         
            +
            require "optparse"
         
     | 
| 
      
 8 
     | 
    
         
            +
            require "erb"
         
     | 
| 
      
 9 
     | 
    
         
            +
            require "fileutils"
         
     | 
| 
       9 
10 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
            require  
     | 
| 
       11 
     | 
    
         
            -
            require  
     | 
| 
       12 
     | 
    
         
            -
            require  
     | 
| 
      
 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,47 @@ 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 
     | 
    
         
            -
                   
     | 
| 
       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 
     | 
    
         
            -
                   
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       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 
     | 
    
         
            -
                     
     | 
| 
       59 
     | 
    
         
            -
                       
     | 
| 
       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:  
     | 
| 
      
 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 
     | 
    
         
            -
                   
     | 
| 
       74 
     | 
    
         
            -
                   
     | 
| 
       75 
     | 
    
         
            -
                   
     | 
| 
      
 62 
     | 
    
         
            +
                  info = Sidekiq.redis_info
         
     | 
| 
      
 63 
     | 
    
         
            +
                  ver = info["redis_version"]
         
     | 
| 
      
 64 
     | 
    
         
            +
                  raise "You are connecting to Redis v#{ver}, Sidekiq requires Redis v4.0.0 or greater" if ver < "4"
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                  maxmemory_policy = info["maxmemory_policy"]
         
     | 
| 
      
 67 
     | 
    
         
            +
                  if maxmemory_policy != "noeviction"
         
     | 
| 
      
 68 
     | 
    
         
            +
                    logger.warn <<~EOM
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
                      WARNING: Your Redis instance will evict Sidekiq data under heavy load.
         
     | 
| 
      
 72 
     | 
    
         
            +
                      The 'noeviction' maxmemory policy is recommended (current policy: '#{maxmemory_policy}').
         
     | 
| 
      
 73 
     | 
    
         
            +
                      See: https://github.com/mperham/sidekiq/wiki/Using-Redis#memory
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
                    EOM
         
     | 
| 
      
 76 
     | 
    
         
            +
                  end
         
     | 
| 
       76 
77 
     | 
    
         | 
| 
       77 
78 
     | 
    
         
             
                  # Since the user can pass us a connection pool explicitly in the initializer, we
         
     | 
| 
       78 
79 
     | 
    
         
             
                  # need to verify the size is large enough or else Sidekiq's performance is dramatically slowed.
         
     | 
| 
         @@ -90,15 +91,15 @@ module Sidekiq 
     | 
|
| 
       90 
91 
     | 
    
         
             
                  # Starting here the process will now have multiple threads running.
         
     | 
| 
       91 
92 
     | 
    
         
             
                  fire_event(:startup, reverse: false, reraise: true)
         
     | 
| 
       92 
93 
     | 
    
         | 
| 
       93 
     | 
    
         
            -
                  logger.debug { "Client Middleware: #{Sidekiq.client_middleware.map(&:klass).join( 
     | 
| 
       94 
     | 
    
         
            -
                  logger.debug { "Server Middleware: #{Sidekiq.server_middleware.map(&:klass).join( 
     | 
| 
      
 94 
     | 
    
         
            +
                  logger.debug { "Client Middleware: #{Sidekiq.client_middleware.map(&:klass).join(", ")}" }
         
     | 
| 
      
 95 
     | 
    
         
            +
                  logger.debug { "Server Middleware: #{Sidekiq.server_middleware.map(&:klass).join(", ")}" }
         
     | 
| 
       95 
96 
     | 
    
         | 
| 
       96 
97 
     | 
    
         
             
                  launch(self_read)
         
     | 
| 
       97 
98 
     | 
    
         
             
                end
         
     | 
| 
       98 
99 
     | 
    
         | 
| 
       99 
100 
     | 
    
         
             
                def launch(self_read)
         
     | 
| 
       100 
     | 
    
         
            -
                  if  
     | 
| 
       101 
     | 
    
         
            -
                    logger.info  
     | 
| 
      
 101 
     | 
    
         
            +
                  if environment == "development" && $stdout.tty?
         
     | 
| 
      
 102 
     | 
    
         
            +
                    logger.info "Starting processing, hit Ctrl-C to stop"
         
     | 
| 
       102 
103 
     | 
    
         
             
                  end
         
     | 
| 
       103 
104 
     | 
    
         | 
| 
       104 
105 
     | 
    
         
             
                  @launcher = Sidekiq::Launcher.new(options)
         
     | 
| 
         @@ -106,121 +107,107 @@ module Sidekiq 
     | 
|
| 
       106 
107 
     | 
    
         
             
                  begin
         
     | 
| 
       107 
108 
     | 
    
         
             
                    launcher.run
         
     | 
| 
       108 
109 
     | 
    
         | 
| 
       109 
     | 
    
         
            -
                    while readable_io = IO.select([self_read])
         
     | 
| 
      
 110 
     | 
    
         
            +
                    while (readable_io = IO.select([self_read]))
         
     | 
| 
       110 
111 
     | 
    
         
             
                      signal = readable_io.first[0].gets.strip
         
     | 
| 
       111 
112 
     | 
    
         
             
                      handle_signal(signal)
         
     | 
| 
       112 
113 
     | 
    
         
             
                    end
         
     | 
| 
       113 
114 
     | 
    
         
             
                  rescue Interrupt
         
     | 
| 
       114 
     | 
    
         
            -
                    logger.info  
     | 
| 
      
 115 
     | 
    
         
            +
                    logger.info "Shutting down"
         
     | 
| 
       115 
116 
     | 
    
         
             
                    launcher.stop
         
     | 
| 
       116 
     | 
    
         
            -
                    # Explicitly exit so busy Processor threads can't block
         
     | 
| 
       117 
     | 
    
         
            -
                    # process shutdown.
         
     | 
| 
       118 
117 
     | 
    
         
             
                    logger.info "Bye!"
         
     | 
| 
      
 118 
     | 
    
         
            +
             
     | 
| 
      
 119 
     | 
    
         
            +
                    # Explicitly exit so busy Processor threads won't block process shutdown.
         
     | 
| 
      
 120 
     | 
    
         
            +
                    #
         
     | 
| 
      
 121 
     | 
    
         
            +
                    # NB: slow at_exit handlers will prevent a timely exit if they take
         
     | 
| 
      
 122 
     | 
    
         
            +
                    # a while to run. If Sidekiq is getting here but the process isn't exiting,
         
     | 
| 
      
 123 
     | 
    
         
            +
                    # use the TTIN signal to determine where things are stuck.
         
     | 
| 
       119 
124 
     | 
    
         
             
                    exit(0)
         
     | 
| 
       120 
125 
     | 
    
         
             
                  end
         
     | 
| 
       121 
126 
     | 
    
         
             
                end
         
     | 
| 
       122 
127 
     | 
    
         | 
| 
      
 128 
     | 
    
         
            +
                def self.w
         
     | 
| 
      
 129 
     | 
    
         
            +
                  "\e[37m"
         
     | 
| 
      
 130 
     | 
    
         
            +
                end
         
     | 
| 
      
 131 
     | 
    
         
            +
             
     | 
| 
      
 132 
     | 
    
         
            +
                def self.r
         
     | 
| 
      
 133 
     | 
    
         
            +
                  "\e[31m"
         
     | 
| 
      
 134 
     | 
    
         
            +
                end
         
     | 
| 
      
 135 
     | 
    
         
            +
             
     | 
| 
      
 136 
     | 
    
         
            +
                def self.b
         
     | 
| 
      
 137 
     | 
    
         
            +
                  "\e[30m"
         
     | 
| 
      
 138 
     | 
    
         
            +
                end
         
     | 
| 
      
 139 
     | 
    
         
            +
             
     | 
| 
      
 140 
     | 
    
         
            +
                def self.reset
         
     | 
| 
      
 141 
     | 
    
         
            +
                  "\e[0m"
         
     | 
| 
      
 142 
     | 
    
         
            +
                end
         
     | 
| 
      
 143 
     | 
    
         
            +
             
     | 
| 
       123 
144 
     | 
    
         
             
                def self.banner
         
     | 
| 
       124 
     | 
    
         
            -
            % 
     | 
| 
       125 
     | 
    
         
            -
                     m,
         
     | 
| 
       126 
     | 
    
         
            -
                     `$b
         
     | 
| 
       127 
     | 
    
         
            -
                .ss,  $$:         .,d$
         
     | 
| 
       128 
     | 
    
         
            -
                `$$P,d$P'    .,md$P"'
         
     | 
| 
       129 
     | 
    
         
            -
                 ,$$$$$ 
     | 
| 
       130 
     | 
    
         
            -
               .d 
     | 
| 
       131 
     | 
    
         
            -
               $$^' `" 
     | 
| 
       132 
     | 
    
         
            -
               $:     ,$$: 
     | 
| 
       133 
     | 
    
         
            -
               `b     :$$ 
     | 
| 
       134 
     | 
    
         
            -
                      $$: 
     | 
| 
       135 
     | 
    
         
            -
                      $$         |____/|_ 
     | 
| 
       136 
     | 
    
         
            -
                    .d$$ 
     | 
| 
       137 
     | 
    
         
            -
            }
         
     | 
| 
      
 145 
     | 
    
         
            +
                  %{
         
     | 
| 
      
 146 
     | 
    
         
            +
                  #{w}         m,
         
     | 
| 
      
 147 
     | 
    
         
            +
                  #{w}         `$b
         
     | 
| 
      
 148 
     | 
    
         
            +
                  #{w}    .ss,  $$:         .,d$
         
     | 
| 
      
 149 
     | 
    
         
            +
                  #{w}    `$$P,d$P'    .,md$P"'
         
     | 
| 
      
 150 
     | 
    
         
            +
                  #{w}     ,$$$$$b#{b}/#{w}md$$$P^'
         
     | 
| 
      
 151 
     | 
    
         
            +
                  #{w}   .d$$$$$$#{b}/#{w}$$$P'
         
     | 
| 
      
 152 
     | 
    
         
            +
                  #{w}   $$^' `"#{b}/#{w}$$$'       #{r}____  _     _      _    _
         
     | 
| 
      
 153 
     | 
    
         
            +
                  #{w}   $:     ,$$:      #{r} / ___|(_) __| | ___| | _(_) __ _
         
     | 
| 
      
 154 
     | 
    
         
            +
                  #{w}   `b     :$$       #{r} \\___ \\| |/ _` |/ _ \\ |/ / |/ _` |
         
     | 
| 
      
 155 
     | 
    
         
            +
                  #{w}          $$:        #{r} ___) | | (_| |  __/   <| | (_| |
         
     | 
| 
      
 156 
     | 
    
         
            +
                  #{w}          $$         #{r}|____/|_|\\__,_|\\___|_|\\_\\_|\\__, |
         
     | 
| 
      
 157 
     | 
    
         
            +
                  #{w}        .d$$          #{r}                             |_|
         
     | 
| 
      
 158 
     | 
    
         
            +
                  #{reset}}
         
     | 
| 
       138 
159 
     | 
    
         
             
                end
         
     | 
| 
       139 
160 
     | 
    
         | 
| 
       140 
161 
     | 
    
         
             
                SIGNAL_HANDLERS = {
         
     | 
| 
       141 
162 
     | 
    
         
             
                  # Ctrl-C in terminal
         
     | 
| 
       142 
     | 
    
         
            -
                   
     | 
| 
      
 163 
     | 
    
         
            +
                  "INT" => ->(cli) { raise Interrupt },
         
     | 
| 
       143 
164 
     | 
    
         
             
                  # TERM is the signal that Sidekiq must exit.
         
     | 
| 
       144 
165 
     | 
    
         
             
                  # Heroku sends TERM and then waits 30 seconds for process to exit.
         
     | 
| 
       145 
     | 
    
         
            -
                   
     | 
| 
       146 
     | 
    
         
            -
                   
     | 
| 
       147 
     | 
    
         
            -
                    Sidekiq.logger.info "Received USR1, no longer accepting new work"
         
     | 
| 
       148 
     | 
    
         
            -
                    cli.launcher.quiet
         
     | 
| 
       149 
     | 
    
         
            -
                  },
         
     | 
| 
       150 
     | 
    
         
            -
                  'TSTP' => ->(cli) {
         
     | 
| 
      
 166 
     | 
    
         
            +
                  "TERM" => ->(cli) { raise Interrupt },
         
     | 
| 
      
 167 
     | 
    
         
            +
                  "TSTP" => ->(cli) {
         
     | 
| 
       151 
168 
     | 
    
         
             
                    Sidekiq.logger.info "Received TSTP, no longer accepting new work"
         
     | 
| 
       152 
169 
     | 
    
         
             
                    cli.launcher.quiet
         
     | 
| 
       153 
170 
     | 
    
         
             
                  },
         
     | 
| 
       154 
     | 
    
         
            -
                   
     | 
| 
       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) {
         
     | 
| 
      
 171 
     | 
    
         
            +
                  "TTIN" => ->(cli) {
         
     | 
| 
       161 
172 
     | 
    
         
             
                    Thread.list.each do |thread|
         
     | 
| 
       162 
     | 
    
         
            -
                      Sidekiq.logger.warn "Thread TID-#{(thread.object_id ^ ::Process.pid).to_s(36)} #{thread 
     | 
| 
      
 173 
     | 
    
         
            +
                      Sidekiq.logger.warn "Thread TID-#{(thread.object_id ^ ::Process.pid).to_s(36)} #{thread.name}"
         
     | 
| 
       163 
174 
     | 
    
         
             
                      if thread.backtrace
         
     | 
| 
       164 
175 
     | 
    
         
             
                        Sidekiq.logger.warn thread.backtrace.join("\n")
         
     | 
| 
       165 
176 
     | 
    
         
             
                      else
         
     | 
| 
       166 
177 
     | 
    
         
             
                        Sidekiq.logger.warn "<no backtrace available>"
         
     | 
| 
       167 
178 
     | 
    
         
             
                      end
         
     | 
| 
       168 
179 
     | 
    
         
             
                    end
         
     | 
| 
       169 
     | 
    
         
            -
                  } 
     | 
| 
      
 180 
     | 
    
         
            +
                  }
         
     | 
| 
       170 
181 
     | 
    
         
             
                }
         
     | 
| 
      
 182 
     | 
    
         
            +
                UNHANDLED_SIGNAL_HANDLER = ->(cli) { Sidekiq.logger.info "No signal handler registered, ignoring" }
         
     | 
| 
      
 183 
     | 
    
         
            +
                SIGNAL_HANDLERS.default = UNHANDLED_SIGNAL_HANDLER
         
     | 
| 
       171 
184 
     | 
    
         | 
| 
       172 
185 
     | 
    
         
             
                def handle_signal(sig)
         
     | 
| 
       173 
186 
     | 
    
         
             
                  Sidekiq.logger.debug "Got #{sig} signal"
         
     | 
| 
       174 
     | 
    
         
            -
                   
     | 
| 
       175 
     | 
    
         
            -
                  if handy
         
     | 
| 
       176 
     | 
    
         
            -
                    handy.call(self)
         
     | 
| 
       177 
     | 
    
         
            -
                  else
         
     | 
| 
       178 
     | 
    
         
            -
                    Sidekiq.logger.info { "No signal handler for #{sig}" }
         
     | 
| 
       179 
     | 
    
         
            -
                  end
         
     | 
| 
      
 187 
     | 
    
         
            +
                  SIGNAL_HANDLERS[sig].call(self)
         
     | 
| 
       180 
188 
     | 
    
         
             
                end
         
     | 
| 
       181 
189 
     | 
    
         | 
| 
       182 
190 
     | 
    
         
             
                private
         
     | 
| 
       183 
191 
     | 
    
         | 
| 
       184 
192 
     | 
    
         
             
                def print_banner
         
     | 
| 
       185 
     | 
    
         
            -
                  puts "\e[ 
     | 
| 
      
 193 
     | 
    
         
            +
                  puts "\e[31m"
         
     | 
| 
       186 
194 
     | 
    
         
             
                  puts Sidekiq::CLI.banner
         
     | 
| 
       187 
195 
     | 
    
         
             
                  puts "\e[0m"
         
     | 
| 
       188 
196 
     | 
    
         
             
                end
         
     | 
| 
       189 
197 
     | 
    
         | 
| 
       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 
198 
     | 
    
         
             
                def set_environment(cli_env)
         
     | 
| 
       216 
     | 
    
         
            -
                   
     | 
| 
      
 199 
     | 
    
         
            +
                  # See #984 for discussion.
         
     | 
| 
      
 200 
     | 
    
         
            +
                  # APP_ENV is now the preferred ENV term since it is not tech-specific.
         
     | 
| 
      
 201 
     | 
    
         
            +
                  # Both Sinatra 2.0+ and Sidekiq support this term.
         
     | 
| 
      
 202 
     | 
    
         
            +
                  # RAILS_ENV and RACK_ENV are there for legacy support.
         
     | 
| 
      
 203 
     | 
    
         
            +
                  @environment = cli_env || ENV["APP_ENV"] || ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
         
     | 
| 
       217 
204 
     | 
    
         
             
                end
         
     | 
| 
       218 
205 
     | 
    
         | 
| 
       219 
206 
     | 
    
         
             
                def symbolize_keys_deep!(hash)
         
     | 
| 
       220 
207 
     | 
    
         
             
                  hash.keys.each do |k|
         
     | 
| 
       221 
208 
     | 
    
         
             
                    symkey = k.respond_to?(:to_sym) ? k.to_sym : k
         
     | 
| 
       222 
209 
     | 
    
         
             
                    hash[symkey] = hash.delete k
         
     | 
| 
       223 
     | 
    
         
            -
                    symbolize_keys_deep! hash[symkey] if hash[symkey]. 
     | 
| 
      
 210 
     | 
    
         
            +
                    symbolize_keys_deep! hash[symkey] if hash[symkey].is_a? Hash
         
     | 
| 
       224 
211 
     | 
    
         
             
                  end
         
     | 
| 
       225 
212 
     | 
    
         
             
                end
         
     | 
| 
       226 
213 
     | 
    
         | 
| 
         @@ -235,14 +222,14 @@ module Sidekiq 
     | 
|
| 
       235 
222 
     | 
    
         | 
| 
       236 
223 
     | 
    
         
             
                  # check config file presence
         
     | 
| 
       237 
224 
     | 
    
         
             
                  if opts[:config_file]
         
     | 
| 
       238 
     | 
    
         
            -
                     
     | 
| 
      
 225 
     | 
    
         
            +
                    unless File.exist?(opts[:config_file])
         
     | 
| 
       239 
226 
     | 
    
         
             
                      raise ArgumentError, "No such file #{opts[:config_file]}"
         
     | 
| 
       240 
227 
     | 
    
         
             
                    end
         
     | 
| 
       241 
228 
     | 
    
         
             
                  else
         
     | 
| 
       242 
229 
     | 
    
         
             
                    config_dir = if File.directory?(opts[:require].to_s)
         
     | 
| 
       243 
     | 
    
         
            -
                      File.join(opts[:require],  
     | 
| 
      
 230 
     | 
    
         
            +
                      File.join(opts[:require], "config")
         
     | 
| 
       244 
231 
     | 
    
         
             
                    else
         
     | 
| 
       245 
     | 
    
         
            -
                      File.join(options[:require],  
     | 
| 
      
 232 
     | 
    
         
            +
                      File.join(options[:require], "config")
         
     | 
| 
       246 
233 
     | 
    
         
             
                    end
         
     | 
| 
       247 
234 
     | 
    
         | 
| 
       248 
235 
     | 
    
         
             
                    %w[sidekiq.yml sidekiq.yml.erb].each do |config_file|
         
     | 
| 
         @@ -255,8 +242,7 @@ module Sidekiq 
     | 
|
| 
       255 
242 
     | 
    
         
             
                  opts = parse_config(opts[:config_file]).merge(opts) if opts[:config_file]
         
     | 
| 
       256 
243 
     | 
    
         | 
| 
       257 
244 
     | 
    
         
             
                  # set defaults
         
     | 
| 
       258 
     | 
    
         
            -
                  opts[:queues] =  
     | 
| 
       259 
     | 
    
         
            -
                  opts[:strict] = true if opts[:strict].nil?
         
     | 
| 
      
 245 
     | 
    
         
            +
                  opts[:queues] = ["default"] if opts[:queues].nil?
         
     | 
| 
       260 
246 
     | 
    
         
             
                  opts[:concurrency] = Integer(ENV["RAILS_MAX_THREADS"]) if opts[:concurrency].nil? && ENV["RAILS_MAX_THREADS"]
         
     | 
| 
       261 
247 
     | 
    
         | 
| 
       262 
248 
     | 
    
         
             
                  # merge with defaults
         
     | 
| 
         @@ -267,24 +253,15 @@ module Sidekiq 
     | 
|
| 
       267 
253 
     | 
    
         
             
                  Sidekiq.options
         
     | 
| 
       268 
254 
     | 
    
         
             
                end
         
     | 
| 
       269 
255 
     | 
    
         | 
| 
       270 
     | 
    
         
            -
                def  
     | 
| 
       271 
     | 
    
         
            -
                  ENV[ 
     | 
| 
      
 256 
     | 
    
         
            +
                def boot_application
         
     | 
| 
      
 257 
     | 
    
         
            +
                  ENV["RACK_ENV"] = ENV["RAILS_ENV"] = environment
         
     | 
| 
       272 
258 
     | 
    
         | 
| 
       273 
259 
     | 
    
         
             
                  if File.directory?(options[:require])
         
     | 
| 
       274 
     | 
    
         
            -
                    require  
     | 
| 
       275 
     | 
    
         
            -
                    if ::Rails::VERSION::MAJOR <  
     | 
| 
      
 260 
     | 
    
         
            +
                    require "rails"
         
     | 
| 
      
 261 
     | 
    
         
            +
                    if ::Rails::VERSION::MAJOR < 5
         
     | 
| 
       276 
262 
     | 
    
         
             
                      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 
263 
     | 
    
         
             
                    else
         
     | 
| 
       287 
     | 
    
         
            -
                      require  
     | 
| 
      
 264 
     | 
    
         
            +
                      require "sidekiq/rails"
         
     | 
| 
       288 
265 
     | 
    
         
             
                      require File.expand_path("#{options[:require]}/config/environment.rb")
         
     | 
| 
       289 
266 
     | 
    
         
             
                    end
         
     | 
| 
       290 
267 
     | 
    
         
             
                    options[:tag] ||= default_tag
         
     | 
| 
         @@ -296,8 +273,9 @@ module Sidekiq 
     | 
|
| 
       296 
273 
     | 
    
         
             
                def default_tag
         
     | 
| 
       297 
274 
     | 
    
         
             
                  dir = ::Rails.root
         
     | 
| 
       298 
275 
     | 
    
         
             
                  name = File.basename(dir)
         
     | 
| 
       299 
     | 
    
         
            -
                   
     | 
| 
       300 
     | 
    
         
            -
             
     | 
| 
      
 276 
     | 
    
         
            +
                  prevdir = File.dirname(dir) # Capistrano release directory?
         
     | 
| 
      
 277 
     | 
    
         
            +
                  if name.to_i != 0 && prevdir
         
     | 
| 
      
 278 
     | 
    
         
            +
                    if File.basename(prevdir) == "releases"
         
     | 
| 
       301 
279 
     | 
    
         
             
                      return File.basename(File.dirname(prevdir))
         
     | 
| 
       302 
280 
     | 
    
         
             
                    end
         
     | 
| 
       303 
281 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -306,9 +284,9 @@ module Sidekiq 
     | 
|
| 
       306 
284 
     | 
    
         | 
| 
       307 
285 
     | 
    
         
             
                def validate!
         
     | 
| 
       308 
286 
     | 
    
         
             
                  if !File.exist?(options[:require]) ||
         
     | 
| 
       309 
     | 
    
         
            -
             
     | 
| 
      
 287 
     | 
    
         
            +
                      (File.directory?(options[:require]) && !File.exist?("#{options[:require]}/config/application.rb"))
         
     | 
| 
       310 
288 
     | 
    
         
             
                    logger.info "=================================================================="
         
     | 
| 
       311 
     | 
    
         
            -
                    logger.info "  Please point  
     | 
| 
      
 289 
     | 
    
         
            +
                    logger.info "  Please point Sidekiq to a Rails application or a Ruby file  "
         
     | 
| 
       312 
290 
     | 
    
         
             
                    logger.info "  to load your worker classes with -r [DIR|FILE]."
         
     | 
| 
       313 
291 
     | 
    
         
             
                    logger.info "=================================================================="
         
     | 
| 
       314 
292 
     | 
    
         
             
                    logger.info @parser
         
     | 
| 
         @@ -316,47 +294,45 @@ module Sidekiq 
     | 
|
| 
       316 
294 
     | 
    
         
             
                  end
         
     | 
| 
       317 
295 
     | 
    
         | 
| 
       318 
296 
     | 
    
         
             
                  [:concurrency, :timeout].each do |opt|
         
     | 
| 
       319 
     | 
    
         
            -
                    raise ArgumentError, "#{opt}: #{options[opt]} is not a valid value" if options. 
     | 
| 
      
 297 
     | 
    
         
            +
                    raise ArgumentError, "#{opt}: #{options[opt]} is not a valid value" if options.key?(opt) && options[opt].to_i <= 0
         
     | 
| 
       320 
298 
     | 
    
         
             
                  end
         
     | 
| 
       321 
299 
     | 
    
         
             
                end
         
     | 
| 
       322 
300 
     | 
    
         | 
| 
       323 
301 
     | 
    
         
             
                def parse_options(argv)
         
     | 
| 
       324 
302 
     | 
    
         
             
                  opts = {}
         
     | 
| 
      
 303 
     | 
    
         
            +
                  @parser = option_parser(opts)
         
     | 
| 
      
 304 
     | 
    
         
            +
                  @parser.parse!(argv)
         
     | 
| 
      
 305 
     | 
    
         
            +
                  opts
         
     | 
| 
      
 306 
     | 
    
         
            +
                end
         
     | 
| 
       325 
307 
     | 
    
         | 
| 
       326 
     | 
    
         
            -
             
     | 
| 
       327 
     | 
    
         
            -
             
     | 
| 
      
 308 
     | 
    
         
            +
                def option_parser(opts)
         
     | 
| 
      
 309 
     | 
    
         
            +
                  parser = OptionParser.new { |o|
         
     | 
| 
      
 310 
     | 
    
         
            +
                    o.on "-c", "--concurrency INT", "processor threads to use" do |arg|
         
     | 
| 
       328 
311 
     | 
    
         
             
                      opts[:concurrency] = Integer(arg)
         
     | 
| 
       329 
312 
     | 
    
         
             
                    end
         
     | 
| 
       330 
313 
     | 
    
         | 
| 
       331 
     | 
    
         
            -
                    o.on  
     | 
| 
       332 
     | 
    
         
            -
                       
     | 
| 
       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"
         
     | 
| 
      
 314 
     | 
    
         
            +
                    o.on "-d", "--daemon", "Daemonize process" do |arg|
         
     | 
| 
      
 315 
     | 
    
         
            +
                      puts "ERROR: Daemonization mode was removed in Sidekiq 6.0, please use a proper process supervisor to start and manage your services"
         
     | 
| 
       334 
316 
     | 
    
         
             
                    end
         
     | 
| 
       335 
317 
     | 
    
         | 
| 
       336 
     | 
    
         
            -
                    o.on  
     | 
| 
      
 318 
     | 
    
         
            +
                    o.on "-e", "--environment ENV", "Application environment" do |arg|
         
     | 
| 
       337 
319 
     | 
    
         
             
                      opts[:environment] = arg
         
     | 
| 
       338 
320 
     | 
    
         
             
                    end
         
     | 
| 
       339 
321 
     | 
    
         | 
| 
       340 
     | 
    
         
            -
                    o.on  
     | 
| 
      
 322 
     | 
    
         
            +
                    o.on "-g", "--tag TAG", "Process tag for procline" do |arg|
         
     | 
| 
       341 
323 
     | 
    
         
             
                      opts[:tag] = arg
         
     | 
| 
       342 
324 
     | 
    
         
             
                    end
         
     | 
| 
       343 
325 
     | 
    
         | 
| 
       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 
326 
     | 
    
         
             
                    o.on "-q", "--queue QUEUE[,WEIGHT]", "Queues to process with optional weights" do |arg|
         
     | 
| 
       351 
327 
     | 
    
         
             
                      queue, weight = arg.split(",")
         
     | 
| 
       352 
328 
     | 
    
         
             
                      parse_queue opts, queue, weight
         
     | 
| 
       353 
329 
     | 
    
         
             
                    end
         
     | 
| 
       354 
330 
     | 
    
         | 
| 
       355 
     | 
    
         
            -
                    o.on  
     | 
| 
      
 331 
     | 
    
         
            +
                    o.on "-r", "--require [PATH|DIR]", "Location of Rails application with workers or file to require" do |arg|
         
     | 
| 
       356 
332 
     | 
    
         
             
                      opts[:require] = arg
         
     | 
| 
       357 
333 
     | 
    
         
             
                    end
         
     | 
| 
       358 
334 
     | 
    
         | 
| 
       359 
     | 
    
         
            -
                    o.on  
     | 
| 
      
 335 
     | 
    
         
            +
                    o.on "-t", "--timeout NUM", "Shutdown timeout" do |arg|
         
     | 
| 
       360 
336 
     | 
    
         
             
                      opts[:timeout] = Integer(arg)
         
     | 
| 
       361 
337 
     | 
    
         
             
                    end
         
     | 
| 
       362 
338 
     | 
    
         | 
| 
         @@ -364,52 +340,37 @@ module Sidekiq 
     | 
|
| 
       364 
340 
     | 
    
         
             
                      opts[:verbose] = arg
         
     | 
| 
       365 
341 
     | 
    
         
             
                    end
         
     | 
| 
       366 
342 
     | 
    
         | 
| 
       367 
     | 
    
         
            -
                    o.on  
     | 
| 
      
 343 
     | 
    
         
            +
                    o.on "-C", "--config PATH", "path to YAML config file" do |arg|
         
     | 
| 
       368 
344 
     | 
    
         
             
                      opts[:config_file] = arg
         
     | 
| 
       369 
345 
     | 
    
         
             
                    end
         
     | 
| 
       370 
346 
     | 
    
         | 
| 
       371 
     | 
    
         
            -
                    o.on  
     | 
| 
       372 
     | 
    
         
            -
                       
     | 
| 
       373 
     | 
    
         
            -
                      puts "WARNING: Logfile redirection will be removed in Sidekiq 6.0, see #4045. Sidekiq will only log to STDOUT"
         
     | 
| 
      
 347 
     | 
    
         
            +
                    o.on "-L", "--logfile PATH", "path to writable logfile" do |arg|
         
     | 
| 
      
 348 
     | 
    
         
            +
                      puts "ERROR: Logfile redirection was removed in Sidekiq 6.0, Sidekiq will only log to STDOUT"
         
     | 
| 
       374 
349 
     | 
    
         
             
                    end
         
     | 
| 
       375 
350 
     | 
    
         | 
| 
       376 
     | 
    
         
            -
                    o.on  
     | 
| 
       377 
     | 
    
         
            -
                       
     | 
| 
       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"
         
     | 
| 
      
 351 
     | 
    
         
            +
                    o.on "-P", "--pidfile PATH", "path to pidfile" do |arg|
         
     | 
| 
      
 352 
     | 
    
         
            +
                      puts "ERROR: PID file creation was removed in Sidekiq 6.0, please use a proper process supervisor to start and manage your services"
         
     | 
| 
       379 
353 
     | 
    
         
             
                    end
         
     | 
| 
       380 
354 
     | 
    
         | 
| 
       381 
     | 
    
         
            -
                    o.on  
     | 
| 
      
 355 
     | 
    
         
            +
                    o.on "-V", "--version", "Print version and exit" do |arg|
         
     | 
| 
       382 
356 
     | 
    
         
             
                      puts "Sidekiq #{Sidekiq::VERSION}"
         
     | 
| 
       383 
357 
     | 
    
         
             
                      die(0)
         
     | 
| 
       384 
358 
     | 
    
         
             
                    end
         
     | 
| 
       385 
     | 
    
         
            -
                   
     | 
| 
      
 359 
     | 
    
         
            +
                  }
         
     | 
| 
       386 
360 
     | 
    
         | 
| 
       387 
     | 
    
         
            -
                   
     | 
| 
       388 
     | 
    
         
            -
                   
     | 
| 
       389 
     | 
    
         
            -
                    logger.info  
     | 
| 
      
 361 
     | 
    
         
            +
                  parser.banner = "sidekiq [options]"
         
     | 
| 
      
 362 
     | 
    
         
            +
                  parser.on_tail "-h", "--help", "Show help" do
         
     | 
| 
      
 363 
     | 
    
         
            +
                    logger.info parser
         
     | 
| 
       390 
364 
     | 
    
         
             
                    die 1
         
     | 
| 
       391 
365 
     | 
    
         
             
                  end
         
     | 
| 
       392 
366 
     | 
    
         | 
| 
       393 
     | 
    
         
            -
                   
     | 
| 
       394 
     | 
    
         
            -
             
     | 
| 
       395 
     | 
    
         
            -
                  opts
         
     | 
| 
      
 367 
     | 
    
         
            +
                  parser
         
     | 
| 
       396 
368 
     | 
    
         
             
                end
         
     | 
| 
       397 
369 
     | 
    
         | 
| 
       398 
370 
     | 
    
         
             
                def initialize_logger
         
     | 
| 
       399 
     | 
    
         
            -
                  Sidekiq::Logging.initialize_logger(options[:logfile]) if options[:logfile]
         
     | 
| 
       400 
     | 
    
         
            -
             
     | 
| 
       401 
371 
     | 
    
         
             
                  Sidekiq.logger.level = ::Logger::DEBUG if options[:verbose]
         
     | 
| 
       402 
372 
     | 
    
         
             
                end
         
     | 
| 
       403 
373 
     | 
    
         | 
| 
       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 
374 
     | 
    
         
             
                def parse_config(path)
         
     | 
| 
       414 
375 
     | 
    
         
             
                  opts = YAML.load(ERB.new(File.read(path)).result) || {}
         
     | 
| 
       415 
376 
     | 
    
         | 
| 
         @@ -420,14 +381,10 @@ module Sidekiq 
     | 
|
| 
       420 
381 
     | 
    
         
             
                  end
         
     | 
| 
       421 
382 
     | 
    
         | 
| 
       422 
383 
     | 
    
         
             
                  opts = opts.merge(opts.delete(environment.to_sym) || {})
         
     | 
| 
      
 384 
     | 
    
         
            +
                  opts.delete(:strict)
         
     | 
| 
      
 385 
     | 
    
         
            +
             
     | 
| 
       423 
386 
     | 
    
         
             
                  parse_queues(opts, opts.delete(:queues) || [])
         
     | 
| 
       424 
387 
     | 
    
         | 
| 
       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 
388 
     | 
    
         
             
                  opts
         
     | 
| 
       432 
389 
     | 
    
         
             
                end
         
     | 
| 
       433 
390 
     | 
    
         | 
| 
         @@ -437,9 +394,16 @@ module Sidekiq 
     | 
|
| 
       437 
394 
     | 
    
         | 
| 
       438 
395 
     | 
    
         
             
                def parse_queue(opts, queue, weight = nil)
         
     | 
| 
       439 
396 
     | 
    
         
             
                  opts[:queues] ||= []
         
     | 
| 
      
 397 
     | 
    
         
            +
                  opts[:strict] = true if opts[:strict].nil?
         
     | 
| 
       440 
398 
     | 
    
         
             
                  raise ArgumentError, "queues: #{queue} cannot be defined twice" if opts[:queues].include?(queue)
         
     | 
| 
       441 
399 
     | 
    
         
             
                  [weight.to_i, 1].max.times { opts[:queues] << queue }
         
     | 
| 
       442 
400 
     | 
    
         
             
                  opts[:strict] = false if weight.to_i > 0
         
     | 
| 
       443 
401 
     | 
    
         
             
                end
         
     | 
| 
      
 402 
     | 
    
         
            +
             
     | 
| 
      
 403 
     | 
    
         
            +
                def rails_app?
         
     | 
| 
      
 404 
     | 
    
         
            +
                  defined?(::Rails) && ::Rails.respond_to?(:application)
         
     | 
| 
      
 405 
     | 
    
         
            +
                end
         
     | 
| 
       444 
406 
     | 
    
         
             
              end
         
     | 
| 
       445 
407 
     | 
    
         
             
            end
         
     | 
| 
      
 408 
     | 
    
         
            +
             
     | 
| 
      
 409 
     | 
    
         
            +
            require "sidekiq/systemd"
         
     |