calling a method to check if a file exists after delayed job is done -RAILS

344 views Asked by At

I have a method that calls a delayed job to create zip files and stores them at a specific folder.now i know that the when the client clicks on the download zip button,this request will be lost as the process will be sent to background job.So when the zip is generated i cannot use send_file/send_data.now i want to use the send_file to send it to the user,hence after the delayed job is done,how can i further implement the logic to send that file to the user.Should i have to check whether the file is generated and then send it(using some recurring method call) or is there any other way to achieve this???i am ruby 1.9 and rails 2.3.

1

There are 1 answers

1
Erica Tripp On BEST ANSWER

If you don't want to make the user wait for the delayed job to finish to do other things, then you'll have to periodically check for the completion of the delayed job (or the resulting zip file).

There are a few gems that handle some of the checking for you, or you can just use some javascript to call a controller action to check for the job results.

e.g.

$(document).ready(
  function(){
    setInterval(function(){
      $('#div_id').load('/my_controller/action_to_look_for_result');
    }, 5000);
});