Sergei Struk
Sergei Struk

Reputation: 358

send_file in delayed_job class

I generate xls-file in background with help of delayed_job gem. After this I would like to send file to the user. Is there some way to call send_file method outside of controller in delayed_job class?

Upvotes: 1

Views: 1016

Answers (1)

user1454117
user1454117

Reputation:

If you are backgrounding a task to delayed_job, then the user's request will no longer exist. If it does still exist, then you don't need to background the task at all (because it defeats the whole purpose of backgrounding).

My recommendation is to save the file off to disk with a corresponding database record once delayed_job generates it. While the user waits, have Ajax occasionally asking the server if the file is ready. When it is ready, use Ajax to make a new request for the file, display a download link, or whatever works best.

Upvotes: 4

Related Questions