Jermila Dhas
Jermila Dhas

Reputation: 11

Automatic reload of page when Sinatra app crashes (when thin server stops)

I have quite recently started playing with Sinatra framework routes (because of Dashing.io project). My question is as follows:

I have dashing running on my local machine. And I have my dashboard open at http://localhost:3030/sample. Say I stop dashing (ctrl+c, which stops thin server as well). And my dashboard still sits there, with widgets on the screen, and I receive an error messages ONLY when I refresh my browser.

Is there a way to automatically redirect to an error page (saying service is down) when dashing goes down or when thin server stops?

Things that I have tried: I had a python script run every sec to check if there are any thin/ dashing processes running. If no process found, I tried using dashing's reload widget to reload the page. But later I realized that I cant use the widget coz dashing is down.

And I did a fair bit of googling to find an answer, but found none. Can anybody please point me in the right direction please?

Upvotes: 1

Views: 418

Answers (1)

tylermauthe
tylermauthe

Reputation: 488

Dashing tries to gracefully handle connection issues with the SSE (server-sent event) that it uses to get widget data. This works well for production, but I can see how it could be confusing during development.

There are a few options I can think of for this, all client-side:

  • Get a browser add-on like this one
  • Create a widget that tracks a heartbeat sent to it from a job and responds to failure (by reloading or something)

Unfortunately, Dashing doesn't expose the EventSource at all. Another option would be to attach your own error handler to that.

There is some code in Dashing that will eventually try to refresh if there is a total failure: https://github.com/Shopify/dashing/blob/c49e181cdb13d3357d76759e5311746ffe00f281/javascripts/dashing.coffee#L104-L110

If the connection is completely lost, Dashing will try to refresh in 5 minutes.

Upvotes: 2

Related Questions