Sha256: 80ddc3c285c7aa862a66453d08c4213507074d1fac3225f5d0ea9d0e93d8b5bd

Contents?: true

Size: 634 Bytes

Versions: 1

Compression:

Stored size: 634 Bytes

Contents

module Sidekiq
  module ThrottledWorker
    class Fetch < Sidekiq::BasicFetch
      alias original_retrieve_work retrieve_work

      def retrieve_work
        work = original_retrieve_work
        return work if work.nil?

        job_hash = Sidekiq.load_json(work.job)
        worker_class = Object.const_get(job_hash['class'])
        return work if worker_class.get_sidekiq_options["concurrency"].nil?

        if Concurrency.limit?(worker_class, job_hash['jid'])
          sleep(rand * 0.1) # wait 100ms to reduce redis qps
          work.requeue
          nil
        else
          work
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sidekiq-throttled-worker-0.1.0 lib/sidekiq/throttled_worker/fetch.rb