Alex
Alex

Reputation: 317

Asynchronous page loading in rails with infinite loop

I have a bot running an infinite loop in rails. I want to have things in the code periodically print to the view page as its running. Since I am having the bot run on an infinite loop I need some way to asynchronously load the page that will output the periodic updates of its actions. What is the best way to do this in rails?

Upvotes: 0

Views: 312

Answers (1)

vereecjw
vereecjw

Reputation: 139

Let me cover 3 different approaches you can take:

  1. Javascript refresh every period of time
  2. Sockets
  3. Prebuild dashboards

Javascript refresh would be simply adding:

 setTimeout(function(){
   window.location.reload(1);
  }, 5000);

or

<meta http-equiv="refresh" content="5; URL=http://www.yourdomain.com/yoursite.html">

as discussed on the question located at: How to reload page every 5 second?

For websockets you can do a direct connection. We use https://github.com/websocket-rails/websocket-rails for our production environment.

Finally for a dashboard you may want to consider: https://github.com/gottfrois/dashing-rails It is phenomenally easy to setup and get going. It does pump the data right to the client but allows you to skip a lot of the nitty gritty and just get running. As a warning, we had issues mixing this with other items and that is why we do not use it on production.

Upvotes: 1

Related Questions