ruby on rails - Trigger the reloading of a page after a background job -


i have rails 4 application, doing background calculus. user press button , launches background job long calculus (using delay_job) , arrive on waiting page. despite fact calculus done asynchronously, find way warn user , automatically reload page once calculus finish.

i have looked @ several solutions :

  • faye or private_pub => can't afford use server specific job
  • actioncontroller::live => not sure how trigger action once job finished
  • polling => best solution moment, expect find less greedy polling

if have smart solution problem, or advise limitation in listed ideas.

i'll explain how works you


http

when send request rails, browser doesn't have way "listen" happens other direct response. http request "sent" & doesn't have mechanism wait until asynchronous process complete

your job give app "listener" front-end can receive updates generated (out of scope of http), hence websocket or sse stuff

we've set you're looking before, using pusher


"live"

achieving "live" functionality need

this means keeping request open "perpetually" server; listening of "events" server sends back. done js on front-end, client "subscribe" channel (typically user-centric one), , have data sent it

we used third-party system called pusher achieve recently:

#gemfile gem "pusher", "~> 0.12.0"      #app/controllers/message.rb def send_message     public_key = self.user.public_key     pusher['private-user-' + public_key].trigger('message_sent', {         message: "message sent"     })   end     #app/assets/javascripts/application.js    pusher = new pusher("***********",      cluster: 'eu'    )     channel = pusher.subscribe("private-user-#{gon.user}")    channel.bind "message_sent", (data) ->     alert data.message 

hope gives option you


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -