Forum: Ruby on Rails warning users that the site is coming down for maintenance

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9d12e24c0a3aebe28b58682d517acdfb?d=identicon&s=25 ybernet@msn.com (Guest)
on 2009-02-27 21:28
(Received via mailing list)
Hi. I have a site that is currently running in alpha mode. I have
warned my users that it will be bouncing up and down as I deploy
updates. That said, i'd like to broadcast a real time warning to them
when I am about to do so. Something along the lines of:

The site will be brought down for maintenance in five minutes. Save
your work and logout to avoid losing data.

Any clever suggestions on how to do this?

A colleague suggested to me that I have a javascript on each page that
polls the server for a change in status and pos up an alert. I'm
looking for other creative suggestions...

Thanks,
Yoram
0d56133042e4814c1b2255ea655f2361?d=identicon&s=25 Jeff Burlysystems (jburly)
on 2009-03-01 03:13
(Received via mailing list)
Hi Yoram,

There are lots of different approaches, especially depending on what
your app does and how it is implemented, but I usually do something
like the following, which works for both development env (setup to re-
reload all code/templates/etc on each request) and production env
(setup to re-load code/templates/etc on app restart):

### in ./app/controllers/application.rb
  ...
  require 'time'
  ...
  MAINT_DOWN_TIME_FILE = "#{RAILS_ROOT}/tmp/down_time_#
{RAILS_ENV}.txt"
  ...
  before_filter :fetch_maint_down_time
  ...
  def fetch_maint_down_time
    @maint_down_time = nil
    begin
      s = IO.read(MAINT_DOWN_TIME_FILE)
      @maint_down_time = Time.parse(s) if s && s =~ /\d/
    rescue
      #ignore, ... meaning no scheduled down time.
    end
  end
  ...

### in ./app/views/shared/_maintenance_msg.html.erb:
<% if @maint_down_time -%>
<%   mins = (@maint_down_time - Time.now).to_i/60 -%>
<%   down_when = mins > 1 ? "in #{mins} minutes" : "imminently" -%>
<div id='sys_notice'>
  Notice: App going offline <%= h(down_when) %>. ...
</div>
<% end -%>

### in each layout, like ./app/views/layouts/testapp.html.erb:
  ...
  <%= render :partial=> 'shared/maintenance_msg' %>
  ...

Then anytime you want to warn your users for a given env about a
planned maint down_time, you just stuff a parsable datetime in the
appropriate env down time file, like:

$ echo '2009-02-28 18:20:00' > ./tmp/down_time_production.txt

which will automatically get picked up with the next request, and thus
will display the maint msg on every screen of your app like:

  ...
  Notice: App going offline in 22 minutes. ...
  ...

And then once you've completed your maintenance, you just clear out
that down time file:

$ echo '' > ./tmp/down_time_production.txt

and no maintenance msg will be displayed.

Jeff
This topic is locked and can not be replied to.