Sorry for the lack of posts recently. I haven’t really been doing any Rails stuff!
My focus as of late has been on design (css) and search engine optimization. I’ll write more about those too I suppose, but for now just a quick trick I cam up with today that I thougth was kind of neat.
MomentVille growth has been great, so we are upgrading hardware. This will cuase up to an hour of downtime as we migrate. But, that seems unacceptable to me. In reality, it’s only 5 minutes of downtime that is required for one specific thing. One VM is getting moved. It needs to be shut down and copied to new hardware. After it is copied, it can go back up on the original hardware, (5 min) and the rest of the time is getting the new hardware up and altering DNS settings. (55 min).
If we run the original after its’ been copied then any changes made will be lost, but that shouldn’t stop people from being able to READ from the db.
I put together a quick little fix to deal with this. In the main controller that deals with edits I created a protected method:
def check_for_maintenance_mode
respond_to do |format|
format.html {
redirect_to "/index_maintenance.html" and return
}
format.js {
render :update do |page|
page.alert "Nov 26, 2007: MomentVille.com is undergoing scheduled maintenance. " +
"It should last less than 1 hour. " +
"Any changes you try to make during this time will NOT be saved. " +
"We are sorry for any inconvenience."
end
return
}
end
end
I then call it in a before filter for any action that performs an edit:
before_filter :check_for_maintenance_mode, :except => [ :show ]
I save that new controller as: controller.maintenance.rb and wrote a little shell script to update the controller and restart the mongrel cluster. This will put me into ‘maintenance’ mode, and the outcome:
- All parts of the website are viewable.
- If someonetries to make a change that requires a database write they get:
- redirected for an http request
- an alert for an ajax request