title: Throttle Sidekiq jobs in rails
body: <p>I'm in need of throttling my Sidekiq jobs so that I don't get this failure:</p>
  
  <pre><code>2020-04-23T12:36:24.424Z pid=1 tid=osrlydn8x WARN: ActiveJob::DeserializationError: Error while trying to deserialize arguments: could not obtain a connection from the pool within 5.000 seconds (waited 5.000 seconds); all pooled connections were in use
  </code></pre>
  
  <p>Basically, what I'm trying to do is send many IP addresses to Sidekiq, where each IP would be its own job:</p>
  
  <pre><code>ip_array.each do |ip|
    ScanJob.perform_later(@scan, ip, ports)
  end
  </code></pre>
  
  <p>ScanJob then does its thing with each incoming IP address, which may take some time, effectively consuming the Sidekiq worker 'pool', and once consumed, any remaining Jobs fail because all pooled connections are in use, as the error states.</p>
  
  <p>Say for instance, I need to run ScanJob against 50 addresses.  Is there a way to limit the Sidekiq pool size to run 5 at a time and queue the remaining 45.  When those 5 are done, the next 5 run (40 queued jobs remaining) and so on?</p>