title: Sidekiq handling re-queue when processing large data
body: <p><strong>See the updated question below.</strong></p>
  
  <p>Original question:</p>
  
  <p>In my current Rails project, I need to parse large xml/csv data file and save it into mongodb.
  Right now I use this steps:</p>
  
  <ol>
  <li>Receive uploaded file from user, store the data into mongodb</li>
  <li>Use sidekiq to perform async process of the data in mongodb.</li>
  <li>After process finished, delete the raw data.</li>
  </ol>
  
  <p>For small and medium data in localhost, the steps above run well. But in heroku, I use hirefire to dynamically scale worker dyno up and down. When worker still processing the large data, hirefire see empty queue and scale down worker dyno. This send kill signal to the process, and leave the process in incomplete state.</p>
  
  <p>I'm searching a better way to do the parsing, allow the parsing process got killed anytime (saving the current state when receiving kill signal), and allow the process got re-queued.</p>
  
  <p>Right now I'm using Model.delay.parse_file and it don't get re-queued.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>After reading sidekiq wiki, I found <a href="https://github.com/mperham/sidekiq/wiki/Job-Control" rel="nofollow">article about job control</a>. Can anyone explain the code, how it works, and how it preserve it's state when receiving SIGTERM signal and the worker get re-queued?</p>
  
  <p>Is there any alternative way to handle job termination, save current state, and continue right from the last position?</p>
  
  <p>Thanks,</p>