sidekiq 5.2.3 → 6.0.0
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 +5 -5
- data/.circleci/config.yml +61 -0
- data/.gitignore +1 -1
- data/.standard.yml +20 -0
- data/6.0-Upgrade.md +70 -0
- data/COMM-LICENSE +11 -9
- data/Changes.md +61 -0
- data/Ent-2.0-Upgrade.md +37 -0
- data/Ent-Changes.md +27 -1
- data/Gemfile +19 -9
- data/Gemfile.lock +196 -0
- data/Pro-5.0-Upgrade.md +25 -0
- data/Pro-Changes.md +19 -2
- data/README.md +17 -31
- data/Rakefile +6 -4
- data/bin/sidekiqload +27 -23
- data/bin/sidekiqmon +9 -0
- data/lib/generators/sidekiq/templates/worker_test.rb.erb +1 -1
- data/lib/generators/sidekiq/worker_generator.rb +12 -14
- data/lib/sidekiq.rb +56 -43
- data/lib/sidekiq/api.rb +138 -151
- data/lib/sidekiq/cli.rb +141 -206
- data/lib/sidekiq/client.rb +45 -46
- data/lib/sidekiq/delay.rb +5 -6
- data/lib/sidekiq/exception_handler.rb +10 -12
- data/lib/sidekiq/extensions/action_mailer.rb +10 -20
- data/lib/sidekiq/extensions/active_record.rb +9 -7
- data/lib/sidekiq/extensions/class_methods.rb +9 -7
- data/lib/sidekiq/extensions/generic_proxy.rb +4 -4
- data/lib/sidekiq/fetch.rb +5 -6
- data/lib/sidekiq/job_logger.rb +37 -7
- data/lib/sidekiq/job_retry.rb +55 -57
- data/lib/sidekiq/launcher.rb +59 -51
- data/lib/sidekiq/logger.rb +69 -0
- data/lib/sidekiq/manager.rb +7 -9
- data/lib/sidekiq/middleware/chain.rb +3 -2
- data/lib/sidekiq/middleware/i18n.rb +5 -7
- data/lib/sidekiq/monitor.rb +148 -0
- data/lib/sidekiq/paginator.rb +11 -12
- data/lib/sidekiq/processor.rb +68 -58
- data/lib/sidekiq/rails.rb +24 -29
- data/lib/sidekiq/redis_connection.rb +31 -37
- data/lib/sidekiq/scheduled.rb +17 -19
- data/lib/sidekiq/testing.rb +22 -23
- data/lib/sidekiq/testing/inline.rb +2 -1
- data/lib/sidekiq/util.rb +17 -14
- data/lib/sidekiq/version.rb +2 -1
- data/lib/sidekiq/web.rb +41 -49
- data/lib/sidekiq/web/action.rb +14 -10
- data/lib/sidekiq/web/application.rb +61 -58
- data/lib/sidekiq/web/helpers.rb +72 -66
- data/lib/sidekiq/web/router.rb +17 -14
- data/lib/sidekiq/worker.rb +134 -102
- data/sidekiq.gemspec +16 -18
- data/web/assets/javascripts/dashboard.js +2 -21
- data/web/assets/stylesheets/bootstrap.css +1 -1
- data/web/locales/ja.yml +2 -1
- data/web/views/queues.erb +1 -1
- metadata +31 -26
- data/.travis.yml +0 -14
- data/bin/sidekiqctl +0 -237
- data/lib/sidekiq/core_ext.rb +0 -1
- data/lib/sidekiq/logging.rb +0 -122
- data/lib/sidekiq/middleware/server/active_record.rb +0 -23
    
        data/lib/sidekiq/rails.rb
    CHANGED
    
    | @@ -1,34 +1,35 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require "sidekiq/worker"
         | 
| 4 | 
            +
             | 
| 2 5 | 
             
            module Sidekiq
         | 
| 3 6 | 
             
              class Rails < ::Rails::Engine
         | 
| 4 | 
            -
                #  | 
| 5 | 
            -
                #  | 
| 7 | 
            +
                # By including the Options module, we allow AJs to directly control sidekiq features
         | 
| 8 | 
            +
                # via the *sidekiq_options* class method and, for instance, not use AJ's retry system.
         | 
| 9 | 
            +
                # AJ retries don't show up in the Sidekiq UI Retries tab, save any error data, can't be
         | 
| 10 | 
            +
                # manually retried, don't automatically die, etc.
         | 
| 6 11 | 
             
                #
         | 
| 7 | 
            -
                #  | 
| 8 | 
            -
                #  | 
| 9 | 
            -
                #  | 
| 10 | 
            -
                #  | 
| 11 | 
            -
                 | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
                    end
         | 
| 12 | 
            +
                #   class SomeJob < ActiveJob::Base
         | 
| 13 | 
            +
                #     queue_as :default
         | 
| 14 | 
            +
                #     sidekiq_options retry: 3, backtrace: 10
         | 
| 15 | 
            +
                #     def perform
         | 
| 16 | 
            +
                #     end
         | 
| 17 | 
            +
                #   end
         | 
| 18 | 
            +
                initializer "sidekiq.active_job_integration" do
         | 
| 19 | 
            +
                  ActiveSupport.on_load(:active_job) do
         | 
| 20 | 
            +
                    include ::Sidekiq::Worker::Options unless respond_to?(:sidekiq_options)
         | 
| 17 21 | 
             
                  end
         | 
| 18 22 | 
             
                end
         | 
| 19 23 |  | 
| 24 | 
            +
                # This hook happens after all initializers are run, just before returning
         | 
| 25 | 
            +
                # from config/environment.rb back to sidekiq/cli.rb.
         | 
| 26 | 
            +
                # We have to add the reloader after initialize to see if cache_classes has
         | 
| 27 | 
            +
                # been turned on.
         | 
| 28 | 
            +
                #
         | 
| 29 | 
            +
                # None of this matters on the client-side, only within the Sidekiq process itself.
         | 
| 20 30 | 
             
                config.after_initialize do
         | 
| 21 | 
            -
                  # This hook happens after all initializers are run, just before returning
         | 
| 22 | 
            -
                  # from config/environment.rb back to sidekiq/cli.rb.
         | 
| 23 | 
            -
                  # We have to add the reloader after initialize to see if cache_classes has
         | 
| 24 | 
            -
                  # been turned on.
         | 
| 25 | 
            -
                  #
         | 
| 26 | 
            -
                  # None of this matters on the client-side, only within the Sidekiq process itself.
         | 
| 27 | 
            -
                  #
         | 
| 28 31 | 
             
                  Sidekiq.configure_server do |_|
         | 
| 29 | 
            -
                     | 
| 30 | 
            -
                      Sidekiq.options[:reloader] = Sidekiq::Rails::Reloader.new
         | 
| 31 | 
            -
                    end
         | 
| 32 | 
            +
                    Sidekiq.options[:reloader] = Sidekiq::Rails::Reloader.new
         | 
| 32 33 | 
             
                  end
         | 
| 33 34 | 
             
                end
         | 
| 34 35 |  | 
| @@ -47,11 +48,5 @@ module Sidekiq | |
| 47 48 | 
             
                    "#<Sidekiq::Rails::Reloader @app=#{@app.class.name}>"
         | 
| 48 49 | 
             
                  end
         | 
| 49 50 | 
             
                end
         | 
| 50 | 
            -
              end | 
| 51 | 
            +
              end
         | 
| 51 52 | 
             
            end
         | 
| 52 | 
            -
             | 
| 53 | 
            -
            if defined?(::Rails) && ::Rails::VERSION::MAJOR < 4
         | 
| 54 | 
            -
              $stderr.puts("**************************************************")
         | 
| 55 | 
            -
              $stderr.puts("⛔️ WARNING: Sidekiq server is no longer supported by Rails 3.2 - please ensure your server/workers are updated")
         | 
| 56 | 
            -
              $stderr.puts("**************************************************")
         | 
| 57 | 
            -
            end
         | 
| @@ -1,36 +1,38 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            require  | 
| 4 | 
            -
            require  | 
| 2 | 
            +
             | 
| 3 | 
            +
            require "connection_pool"
         | 
| 4 | 
            +
            require "redis"
         | 
| 5 | 
            +
            require "uri"
         | 
| 5 6 |  | 
| 6 7 | 
             
            module Sidekiq
         | 
| 7 8 | 
             
              class RedisConnection
         | 
| 8 9 | 
             
                class << self
         | 
| 9 | 
            -
             | 
| 10 | 
            -
                  def create(options={})
         | 
| 10 | 
            +
                  def create(options = {})
         | 
| 11 11 | 
             
                    options.keys.each do |key|
         | 
| 12 12 | 
             
                      options[key.to_sym] = options.delete(key)
         | 
| 13 13 | 
             
                    end
         | 
| 14 14 |  | 
| 15 | 
            -
                    options[:id] = "Sidekiq-#{Sidekiq.server? ? "server" : "client"}-PID-#{ | 
| 15 | 
            +
                    options[:id] = "Sidekiq-#{Sidekiq.server? ? "server" : "client"}-PID-#{::Process.pid}" unless options.key?(:id)
         | 
| 16 16 | 
             
                    options[:url] ||= determine_redis_provider
         | 
| 17 17 |  | 
| 18 18 | 
             
                    size = if options[:size]
         | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 19 | 
            +
                      options[:size]
         | 
| 20 | 
            +
                    elsif Sidekiq.server?
         | 
| 21 | 
            +
                      # Give ourselves plenty of connections.  pool is lazy
         | 
| 22 | 
            +
                      # so we won't create them until we need them.
         | 
| 23 | 
            +
                      Sidekiq.options[:concurrency] + 5
         | 
| 24 | 
            +
                    elsif ENV["RAILS_MAX_THREADS"]
         | 
| 25 | 
            +
                      Integer(ENV["RAILS_MAX_THREADS"])
         | 
| 26 | 
            +
                    else
         | 
| 27 | 
            +
                      5
         | 
| 28 | 
            +
                    end
         | 
| 27 29 |  | 
| 28 30 | 
             
                    verify_sizing(size, Sidekiq.options[:concurrency]) if Sidekiq.server?
         | 
| 29 31 |  | 
| 30 32 | 
             
                    pool_timeout = options[:pool_timeout] || 1
         | 
| 31 33 | 
             
                    log_info(options)
         | 
| 32 34 |  | 
| 33 | 
            -
                    ConnectionPool.new(: | 
| 35 | 
            +
                    ConnectionPool.new(timeout: pool_timeout, size: size) do
         | 
| 34 36 | 
             
                      build_client(options)
         | 
| 35 37 | 
             
                    end
         | 
| 36 38 | 
             
                  end
         | 
| @@ -46,7 +48,7 @@ module Sidekiq | |
| 46 48 | 
             
                  #   - enterprise's leader election
         | 
| 47 49 | 
             
                  #   - enterprise's cron support
         | 
| 48 50 | 
             
                  def verify_sizing(size, concurrency)
         | 
| 49 | 
            -
                    raise ArgumentError, "Your Redis connection pool is too small for Sidekiq to work. Your pool has #{size} connections but must have at least #{concurrency + 2}" if size  | 
| 51 | 
            +
                    raise ArgumentError, "Your Redis connection pool is too small for Sidekiq to work. Your pool has #{size} connections but must have at least #{concurrency + 2}" if size < (concurrency + 2)
         | 
| 50 52 | 
             
                  end
         | 
| 51 53 |  | 
| 52 54 | 
             
                  def build_client(options)
         | 
| @@ -55,8 +57,8 @@ module Sidekiq | |
| 55 57 | 
             
                    client = Redis.new client_opts(options)
         | 
| 56 58 | 
             
                    if namespace
         | 
| 57 59 | 
             
                      begin
         | 
| 58 | 
            -
                        require  | 
| 59 | 
            -
                        Redis::Namespace.new(namespace, : | 
| 60 | 
            +
                        require "redis/namespace"
         | 
| 61 | 
            +
                        Redis::Namespace.new(namespace, redis: client)
         | 
| 60 62 | 
             
                      rescue LoadError
         | 
| 61 63 | 
             
                        Sidekiq.logger.error("Your Redis configuration uses the namespace '#{namespace}' but the redis-namespace gem is not included in the Gemfile." \
         | 
| 62 64 | 
             
                                             "Add the gem to your Gemfile to continue using a namespace. Otherwise, remove the namespace parameter.")
         | 
| @@ -78,7 +80,7 @@ module Sidekiq | |
| 78 80 | 
             
                      opts.delete(:network_timeout)
         | 
| 79 81 | 
             
                    end
         | 
| 80 82 |  | 
| 81 | 
            -
                    opts[:driver] ||= Redis::Connection.drivers.last ||  | 
| 83 | 
            +
                    opts[:driver] ||= Redis::Connection.drivers.last || "ruby"
         | 
| 82 84 |  | 
| 83 85 | 
             
                    # Issue #3303, redis-rb will silently retry an operation.
         | 
| 84 86 | 
             
                    # This can lead to duplicate jobs if Sidekiq::Client's LPUSH
         | 
| @@ -115,30 +117,22 @@ module Sidekiq | |
| 115 117 | 
             
                    # REDIS_PROVIDER=MY_REDIS_URL
         | 
| 116 118 | 
             
                    # and Sidekiq will find your custom URL variable with no custom
         | 
| 117 119 | 
             
                    # initialization code at all.
         | 
| 118 | 
            -
                     | 
| 120 | 
            +
                    #
         | 
| 121 | 
            +
                    p = ENV["REDIS_PROVIDER"]
         | 
| 119 122 | 
             
                    if p && p =~ /\:/
         | 
| 120 | 
            -
                       | 
| 121 | 
            -
             | 
| 122 | 
            -
             | 
| 123 | 
            -
             | 
| 124 | 
            -
            REDIS_PROVIDER should be set to the **name** of the variable which contains the Redis URL, not a URL itself.
         | 
| 125 | 
            -
            Platforms like Heroku sell addons that publish a *_URL variable.  You tell Sidekiq with REDIS_PROVIDER, e.g.:
         | 
| 123 | 
            +
                      raise <<~EOM
         | 
| 124 | 
            +
                        REDIS_PROVIDER should be set to the name of the variable which contains the Redis URL, not a URL itself.
         | 
| 125 | 
            +
                        Platforms like Heroku will sell addons that publish a *_URL variable.  You need to tell Sidekiq with REDIS_PROVIDER, e.g.:
         | 
| 126 126 |  | 
| 127 | 
            -
             | 
| 128 | 
            -
             | 
| 129 | 
            -
             | 
| 130 | 
            -
            Use REDIS_URL if you wish to point Sidekiq to a URL directly.
         | 
| 131 | 
            -
             | 
| 132 | 
            -
            This configuration error will crash starting in Sidekiq 5.3.
         | 
| 133 | 
            -
             | 
| 134 | 
            -
            #################################################################################
         | 
| 135 | 
            -
            EOM
         | 
| 127 | 
            +
                        REDISTOGO_URL=redis://somehost.example.com:6379/4
         | 
| 128 | 
            +
                        REDIS_PROVIDER=REDISTOGO_URL
         | 
| 129 | 
            +
                      EOM
         | 
| 136 130 | 
             
                    end
         | 
| 131 | 
            +
             | 
| 137 132 | 
             
                    ENV[
         | 
| 138 | 
            -
                       | 
| 133 | 
            +
                      p || "REDIS_URL"
         | 
| 139 134 | 
             
                    ]
         | 
| 140 135 | 
             
                  end
         | 
| 141 | 
            -
             | 
| 142 136 | 
             
                end
         | 
| 143 137 | 
             
              end
         | 
| 144 138 | 
             
            end
         | 
    
        data/lib/sidekiq/scheduled.rb
    CHANGED
    
    | @@ -1,14 +1,15 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            require  | 
| 4 | 
            -
            require  | 
| 2 | 
            +
             | 
| 3 | 
            +
            require "sidekiq"
         | 
| 4 | 
            +
            require "sidekiq/util"
         | 
| 5 | 
            +
            require "sidekiq/api"
         | 
| 5 6 |  | 
| 6 7 | 
             
            module Sidekiq
         | 
| 7 8 | 
             
              module Scheduled
         | 
| 8 | 
            -
                SETS = %w | 
| 9 | 
            +
                SETS = %w[retry schedule]
         | 
| 9 10 |  | 
| 10 11 | 
             
                class Enq
         | 
| 11 | 
            -
                  def enqueue_jobs(now=Time.now.to_f.to_s, sorted_sets=SETS)
         | 
| 12 | 
            +
                  def enqueue_jobs(now = Time.now.to_f.to_s, sorted_sets = SETS)
         | 
| 12 13 | 
             
                    # A job's "score" in Redis is the time at which it should be processed.
         | 
| 13 14 | 
             
                    # Just check Redis for the set of jobs with a timestamp before now.
         | 
| 14 15 | 
             
                    Sidekiq.redis do |conn|
         | 
| @@ -17,14 +18,14 @@ module Sidekiq | |
| 17 18 | 
             
                        # We need to go through the list one at a time to reduce the risk of something
         | 
| 18 19 | 
             
                        # going wrong between the time jobs are popped from the scheduled queue and when
         | 
| 19 20 | 
             
                        # they are pushed onto a work queue and losing the jobs.
         | 
| 20 | 
            -
                        while job = conn.zrangebyscore(sorted_set,  | 
| 21 | 
            +
                        while (job = conn.zrangebyscore(sorted_set, "-inf", now, limit: [0, 1]).first)
         | 
| 21 22 |  | 
| 22 23 | 
             
                          # Pop item off the queue and add it to the work queue. If the job can't be popped from
         | 
| 23 24 | 
             
                          # the queue, it's because another process already popped it so we can move on to the
         | 
| 24 25 | 
             
                          # next one.
         | 
| 25 26 | 
             
                          if conn.zrem(sorted_set, job)
         | 
| 26 27 | 
             
                            Sidekiq::Client.push(Sidekiq.load_json(job))
         | 
| 27 | 
            -
                            Sidekiq | 
| 28 | 
            +
                            Sidekiq.logger.debug { "enqueued #{sorted_set}: #{job}" }
         | 
| 28 29 | 
             
                          end
         | 
| 29 30 | 
             
                        end
         | 
| 30 31 | 
             
                      end
         | 
| @@ -61,26 +62,24 @@ module Sidekiq | |
| 61 62 | 
             
                  end
         | 
| 62 63 |  | 
| 63 64 | 
             
                  def start
         | 
| 64 | 
            -
                    @thread ||= safe_thread("scheduler")  | 
| 65 | 
            +
                    @thread ||= safe_thread("scheduler") {
         | 
| 65 66 | 
             
                      initial_wait
         | 
| 66 67 |  | 
| 67 | 
            -
                       | 
| 68 | 
            +
                      until @done
         | 
| 68 69 | 
             
                        enqueue
         | 
| 69 70 | 
             
                        wait
         | 
| 70 71 | 
             
                      end
         | 
| 71 72 | 
             
                      Sidekiq.logger.info("Scheduler exiting...")
         | 
| 72 | 
            -
                     | 
| 73 | 
            +
                    }
         | 
| 73 74 | 
             
                  end
         | 
| 74 75 |  | 
| 75 76 | 
             
                  def enqueue
         | 
| 76 | 
            -
                     | 
| 77 | 
            -
             | 
| 78 | 
            -
                     | 
| 79 | 
            -
             | 
| 80 | 
            -
             | 
| 81 | 
            -
             | 
| 82 | 
            -
                      handle_exception(ex)
         | 
| 83 | 
            -
                    end
         | 
| 77 | 
            +
                    @enq.enqueue_jobs
         | 
| 78 | 
            +
                  rescue => ex
         | 
| 79 | 
            +
                    # Most likely a problem with redis networking.
         | 
| 80 | 
            +
                    # Punt and try again at the next interval
         | 
| 81 | 
            +
                    logger.error ex.message
         | 
| 82 | 
            +
                    handle_exception(ex)
         | 
| 84 83 | 
             
                  end
         | 
| 85 84 |  | 
| 86 85 | 
             
                  private
         | 
| @@ -168,7 +167,6 @@ module Sidekiq | |
| 168 167 | 
             
                    @sleeper.pop(total)
         | 
| 169 168 | 
             
                  rescue Timeout::Error
         | 
| 170 169 | 
             
                  end
         | 
| 171 | 
            -
             | 
| 172 170 | 
             
                end
         | 
| 173 171 | 
             
              end
         | 
| 174 172 | 
             
            end
         | 
    
        data/lib/sidekiq/testing.rb
    CHANGED
    
    | @@ -1,16 +1,16 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 | 
            -
            require 'securerandom'
         | 
| 3 | 
            -
            require 'sidekiq'
         | 
| 4 2 |  | 
| 5 | 
            -
             | 
| 3 | 
            +
            require "securerandom"
         | 
| 4 | 
            +
            require "sidekiq"
         | 
| 6 5 |  | 
| 6 | 
            +
            module Sidekiq
         | 
| 7 7 | 
             
              class Testing
         | 
| 8 8 | 
             
                class << self
         | 
| 9 9 | 
             
                  attr_accessor :__test_mode
         | 
| 10 10 |  | 
| 11 11 | 
             
                  def __set_test_mode(mode)
         | 
| 12 12 | 
             
                    if block_given?
         | 
| 13 | 
            -
                      current_mode =  | 
| 13 | 
            +
                      current_mode = __test_mode
         | 
| 14 14 | 
             
                      begin
         | 
| 15 15 | 
             
                        self.__test_mode = mode
         | 
| 16 16 | 
             
                        yield
         | 
| @@ -35,19 +35,19 @@ module Sidekiq | |
| 35 35 | 
             
                  end
         | 
| 36 36 |  | 
| 37 37 | 
             
                  def enabled?
         | 
| 38 | 
            -
                     | 
| 38 | 
            +
                    __test_mode != :disable
         | 
| 39 39 | 
             
                  end
         | 
| 40 40 |  | 
| 41 41 | 
             
                  def disabled?
         | 
| 42 | 
            -
                     | 
| 42 | 
            +
                    __test_mode == :disable
         | 
| 43 43 | 
             
                  end
         | 
| 44 44 |  | 
| 45 45 | 
             
                  def fake?
         | 
| 46 | 
            -
                     | 
| 46 | 
            +
                    __test_mode == :fake
         | 
| 47 47 | 
             
                  end
         | 
| 48 48 |  | 
| 49 49 | 
             
                  def inline?
         | 
| 50 | 
            -
                     | 
| 50 | 
            +
                    __test_mode == :inline
         | 
| 51 51 | 
             
                  end
         | 
| 52 52 |  | 
| 53 53 | 
             
                  def server_middleware
         | 
| @@ -57,7 +57,7 @@ module Sidekiq | |
| 57 57 | 
             
                  end
         | 
| 58 58 |  | 
| 59 59 | 
             
                  def constantize(str)
         | 
| 60 | 
            -
                    names = str.split( | 
| 60 | 
            +
                    names = str.split("::")
         | 
| 61 61 | 
             
                    names.shift if names.empty? || names.first.empty?
         | 
| 62 62 |  | 
| 63 63 | 
             
                    names.inject(Object) do |constant, name|
         | 
| @@ -77,14 +77,14 @@ module Sidekiq | |
| 77 77 | 
             
                  if Sidekiq::Testing.fake?
         | 
| 78 78 | 
             
                    payloads.each do |job|
         | 
| 79 79 | 
             
                      job = Sidekiq.load_json(Sidekiq.dump_json(job))
         | 
| 80 | 
            -
                      job | 
| 81 | 
            -
                      Queues.push(job[ | 
| 80 | 
            +
                      job["enqueued_at"] = Time.now.to_f unless job["at"]
         | 
| 81 | 
            +
                      Queues.push(job["queue"], job["class"], job)
         | 
| 82 82 | 
             
                    end
         | 
| 83 83 | 
             
                    true
         | 
| 84 84 | 
             
                  elsif Sidekiq::Testing.inline?
         | 
| 85 85 | 
             
                    payloads.each do |job|
         | 
| 86 | 
            -
                      klass = Sidekiq::Testing.constantize(job[ | 
| 87 | 
            -
                      job[ | 
| 86 | 
            +
                      klass = Sidekiq::Testing.constantize(job["class"])
         | 
| 87 | 
            +
                      job["id"] ||= SecureRandom.hex(12)
         | 
| 88 88 | 
             
                      job_hash = Sidekiq.load_json(Sidekiq.dump_json(job))
         | 
| 89 89 | 
             
                      klass.process_job(job_hash)
         | 
| 90 90 | 
             
                    end
         | 
| @@ -255,27 +255,26 @@ module Sidekiq | |
| 255 255 | 
             
                #   Then I should receive a welcome email to "foo@example.com"
         | 
| 256 256 | 
             
                #
         | 
| 257 257 | 
             
                module ClassMethods
         | 
| 258 | 
            -
             | 
| 259 258 | 
             
                  # Queue for this worker
         | 
| 260 259 | 
             
                  def queue
         | 
| 261 | 
            -
                     | 
| 260 | 
            +
                    get_sidekiq_options["queue"]
         | 
| 262 261 | 
             
                  end
         | 
| 263 262 |  | 
| 264 263 | 
             
                  # Jobs queued for this worker
         | 
| 265 264 | 
             
                  def jobs
         | 
| 266 | 
            -
                    Queues.jobs_by_worker[ | 
| 265 | 
            +
                    Queues.jobs_by_worker[to_s]
         | 
| 267 266 | 
             
                  end
         | 
| 268 267 |  | 
| 269 268 | 
             
                  # Clear all jobs for this worker
         | 
| 270 269 | 
             
                  def clear
         | 
| 271 | 
            -
                    Queues.clear_for(queue,  | 
| 270 | 
            +
                    Queues.clear_for(queue, to_s)
         | 
| 272 271 | 
             
                  end
         | 
| 273 272 |  | 
| 274 273 | 
             
                  # Drain and run all jobs for this worker
         | 
| 275 274 | 
             
                  def drain
         | 
| 276 275 | 
             
                    while jobs.any?
         | 
| 277 276 | 
             
                      next_job = jobs.first
         | 
| 278 | 
            -
                      Queues.delete_for(next_job["jid"], next_job["queue"],  | 
| 277 | 
            +
                      Queues.delete_for(next_job["jid"], next_job["queue"], to_s)
         | 
| 279 278 | 
             
                      process_job(next_job)
         | 
| 280 279 | 
             
                    end
         | 
| 281 280 | 
             
                  end
         | 
| @@ -284,16 +283,16 @@ module Sidekiq | |
| 284 283 | 
             
                  def perform_one
         | 
| 285 284 | 
             
                    raise(EmptyQueueError, "perform_one called with empty job queue") if jobs.empty?
         | 
| 286 285 | 
             
                    next_job = jobs.first
         | 
| 287 | 
            -
                    Queues.delete_for(next_job["jid"], queue,  | 
| 286 | 
            +
                    Queues.delete_for(next_job["jid"], queue, to_s)
         | 
| 288 287 | 
             
                    process_job(next_job)
         | 
| 289 288 | 
             
                  end
         | 
| 290 289 |  | 
| 291 290 | 
             
                  def process_job(job)
         | 
| 292 291 | 
             
                    worker = new
         | 
| 293 | 
            -
                    worker.jid = job[ | 
| 294 | 
            -
                    worker.bid = job[ | 
| 295 | 
            -
                    Sidekiq::Testing.server_middleware.invoke(worker, job, job[ | 
| 296 | 
            -
                      execute_job(worker, job[ | 
| 292 | 
            +
                    worker.jid = job["jid"]
         | 
| 293 | 
            +
                    worker.bid = job["bid"] if worker.respond_to?(:bid=)
         | 
| 294 | 
            +
                    Sidekiq::Testing.server_middleware.invoke(worker, job, job["queue"]) do
         | 
| 295 | 
            +
                      execute_job(worker, job["args"])
         | 
| 297 296 | 
             
                    end
         | 
| 298 297 | 
             
                  end
         | 
| 299 298 |  | 
    
        data/lib/sidekiq/util.rb
    CHANGED
    
    | @@ -1,7 +1,8 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            require  | 
| 4 | 
            -
            require  | 
| 2 | 
            +
             | 
| 3 | 
            +
            require "socket"
         | 
| 4 | 
            +
            require "securerandom"
         | 
| 5 | 
            +
            require "sidekiq/exception_handler"
         | 
| 5 6 |  | 
| 6 7 | 
             
            module Sidekiq
         | 
| 7 8 | 
             
              ##
         | 
| @@ -15,13 +16,13 @@ module Sidekiq | |
| 15 16 | 
             
                def watchdog(last_words)
         | 
| 16 17 | 
             
                  yield
         | 
| 17 18 | 
             
                rescue Exception => ex
         | 
| 18 | 
            -
                  handle_exception(ex, { | 
| 19 | 
            +
                  handle_exception(ex, {context: last_words})
         | 
| 19 20 | 
             
                  raise ex
         | 
| 20 21 | 
             
                end
         | 
| 21 22 |  | 
| 22 23 | 
             
                def safe_thread(name, &block)
         | 
| 23 24 | 
             
                  Thread.new do
         | 
| 24 | 
            -
                    Thread.current | 
| 25 | 
            +
                    Thread.current.name = name
         | 
| 25 26 | 
             
                    watchdog(name, &block)
         | 
| 26 27 | 
             
                  end
         | 
| 27 28 | 
             
                end
         | 
| @@ -34,8 +35,12 @@ module Sidekiq | |
| 34 35 | 
             
                  Sidekiq.redis(&block)
         | 
| 35 36 | 
             
                end
         | 
| 36 37 |  | 
| 38 | 
            +
                def tid
         | 
| 39 | 
            +
                  Thread.current["sidekiq_tid"] ||= (Thread.current.object_id ^ ::Process.pid).to_s(36)
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
             | 
| 37 42 | 
             
                def hostname
         | 
| 38 | 
            -
                  ENV[ | 
| 43 | 
            +
                  ENV["DYNO"] || Socket.gethostname
         | 
| 39 44 | 
             
                end
         | 
| 40 45 |  | 
| 41 46 | 
             
                def process_nonce
         | 
| @@ -43,22 +48,20 @@ module Sidekiq | |
| 43 48 | 
             
                end
         | 
| 44 49 |  | 
| 45 50 | 
             
                def identity
         | 
| 46 | 
            -
                  @@identity ||= "#{hostname}:#{ | 
| 51 | 
            +
                  @@identity ||= "#{hostname}:#{::Process.pid}:#{process_nonce}"
         | 
| 47 52 | 
             
                end
         | 
| 48 53 |  | 
| 49 | 
            -
                def fire_event(event, options={})
         | 
| 54 | 
            +
                def fire_event(event, options = {})
         | 
| 50 55 | 
             
                  reverse = options[:reverse]
         | 
| 51 56 | 
             
                  reraise = options[:reraise]
         | 
| 52 57 |  | 
| 53 58 | 
             
                  arr = Sidekiq.options[:lifecycle_events][event]
         | 
| 54 59 | 
             
                  arr.reverse! if reverse
         | 
| 55 60 | 
             
                  arr.each do |block|
         | 
| 56 | 
            -
                     | 
| 57 | 
            -
             | 
| 58 | 
            -
                     | 
| 59 | 
            -
             | 
| 60 | 
            -
                      raise ex if reraise
         | 
| 61 | 
            -
                    end
         | 
| 61 | 
            +
                    block.call
         | 
| 62 | 
            +
                  rescue => ex
         | 
| 63 | 
            +
                    handle_exception(ex, {context: "Exception during Sidekiq lifecycle event.", event: event})
         | 
| 64 | 
            +
                    raise ex if reraise
         | 
| 62 65 | 
             
                  end
         | 
| 63 66 | 
             
                  arr.clear
         | 
| 64 67 | 
             
                end
         |