Reputation: 19247
My rails 3.2 app has a report page that frequently takes 90+ seconds to render, so I run the report-builder as a delayed_job task then display a "wait a minute" view (with a refresh button) until the content is ready (there is a content_ready
flag used in the view to display either the "wait message" or the report, as appropriate). In my prototype, the user has to refresh the page manually until the content_ready
is set (and then the report view is rendered).
I'd like to have the page refresh automatically when content_ready
is true.
What's the simplest way to accomplish this, given it's a rarely-hit page and thus an inefficient method, such as telling the user's browser to poll the server (or redraw the whole page) every 10 seconds, is just fine?
Upvotes: 0
Views: 338
Reputation: 6419
I'd recommend the following strategy:
It's a pretty simple strategy, but it works.
Upvotes: 1
Reputation: 3911
Setup either a meta-refresh on the page or an ajax updater (if using jquery, see here) that checks a specific controller action that tells you whether the job is completed, or that the file exists in the location expected.
Or, and assuming you're using the delayed_job gem, check out the hooks that are provided as part of the job queuing execution. There is documentation on the gem's GH page.
Upvotes: 1