title: Releasing ActiveRecord connection before the end of a Sidekiq job
body: <p>This question deals with matters of performance and optimization with the way one can implement Sidekiq jobs.</p>
  
  <p>Suppose we have the following job workflow</p>
  
  <blockquote>
    <p>def perform</p>
  
  <pre><code># Step 1
  do_things_with_activerecord_db_and_get_some_parameters()
  
  # Step 2
  step2_perform_an_http_request_with_these_parameters_on_unreliable_server()
  </code></pre>
    
    <p>end</p>
  </blockquote>
  
  <p>In the following case, an ActiveRecord connection is taken from the pool at Step 1, and will only be released by SideKiq after job has completed (or failed) by the ActiveRecord middleware of SideKiq.</p>
  
  <p>Since the external http server at step2 on which we do the request is unreliable, the http request can take a long time or even timeout, and thus the ActiveRecord connection is locked for nothing for all that time, right?</p>
  
  <p>So my question is: Is it pertinent, useful and safe to call:</p>
  
  <blockquote>
    <p>ActiveRecord::Base.clear_active_connections!</p>
  </blockquote>
  
  <p>between Step 1 and Step 2, so that the job frees the resource by itself and make it available for other similar jobs? Or have I missed something about connection pools? Can this method be applied to the redis connection too?</p>
  
  <p>Thanks by advance!</p>