Question

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.

Was it helpful?

Solution

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);
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top