Allow the API to be taken offline completely as well as being put into

readonly mode,
This commit is contained in:
Tom Hughes 2007-09-20 23:51:11 +00:00
parent 27d8f2ef63
commit 9c01c4cb63
11 changed files with 25 additions and 9 deletions

View file

@ -2,7 +2,7 @@ class AmfController < ApplicationController
require 'stringio' require 'stringio'
session :off session :off
before_filter :check_availability before_filter :check_write_availability
# to log: # to log:
# RAILS_DEFAULT_LOGGER.error("Args: #{args[0]}, #{args[1]}, #{args[2]}, #{args[3]}") # RAILS_DEFAULT_LOGGER.error("Args: #{args[0]}, #{args[1]}, #{args[2]}, #{args[3]}")

View file

@ -1,6 +1,7 @@
class ApiController < ApplicationController class ApiController < ApplicationController
session :off session :off
before_filter :check_read_availability, :except => [:capabilities]
after_filter :compress_output after_filter :compress_output
#COUNT is the number of map requests to allow before exiting and starting a new process #COUNT is the number of map requests to allow before exiting and starting a new process

View file

@ -39,8 +39,16 @@ class ApplicationController < ActionController::Base
end end
end end
def check_availability def check_read_availability
if API_READONLY if API_STATUS == :offline
response.headers['Error'] = "Database offline for maintenance"
render :nothing => true, :status => :service_unavailable
return false
end
end
def check_write_availability
if API_STATUS == :offline or API_STATUS == :readonly
response.headers['Error'] = "Database offline for maintenance" response.headers['Error'] = "Database offline for maintenance"
render :nothing => true, :status => :service_unavailable render :nothing => true, :status => :service_unavailable
return false return false

View file

@ -3,7 +3,8 @@ class NodeController < ApplicationController
session :off session :off
before_filter :authorize, :only => [:create, :update, :delete] before_filter :authorize, :only => [:create, :update, :delete]
before_filter :check_availability, :only => [:create, :update, :delete] before_filter :check_write_availability, :only => [:create, :update, :delete]
before_filter :check_read_availability, :except => [:create, :update, :delete]
after_filter :compress_output after_filter :compress_output
def create def create

View file

@ -2,6 +2,7 @@ class OldNodeController < ApplicationController
require 'xml/libxml' require 'xml/libxml'
session :off session :off
before_filter :check_read_availability
after_filter :compress_output after_filter :compress_output
def history def history

View file

@ -2,6 +2,7 @@ class OldSegmentController < ApplicationController
require 'xml/libxml' require 'xml/libxml'
session :off session :off
before_filter :check_read_availability
after_filter :compress_output after_filter :compress_output
def history def history

View file

@ -2,6 +2,7 @@ class OldWayController < ApplicationController
require 'xml/libxml' require 'xml/libxml'
session :off session :off
before_filter :check_read_availability
after_filter :compress_output after_filter :compress_output
def history def history

View file

@ -3,7 +3,8 @@ class SegmentController < ApplicationController
session :off session :off
before_filter :authorize, :only => [:create, :update, :delete] before_filter :authorize, :only => [:create, :update, :delete]
before_filter :check_availability, :only => [:create, :update, :delete] before_filter :check_write_availability, :only => [:create, :update, :delete]
before_filter :check_read_availability, :except => [:create, :update, :delete]
after_filter :compress_output after_filter :compress_output
def create def create

View file

@ -1,6 +1,6 @@
class SwfController < ApplicationController class SwfController < ApplicationController
session :off session :off
before_filter :check_availability before_filter :check_read_availability
# to log: # to log:
# RAILS_DEFAULT_LOGGER.error("Args: #{args[0]}, #{args[1]}, #{args[2]}, #{args[3]}") # RAILS_DEFAULT_LOGGER.error("Args: #{args[0]}, #{args[1]}, #{args[2]}, #{args[3]}")

View file

@ -3,7 +3,8 @@ class WayController < ApplicationController
session :off session :off
before_filter :authorize, :only => [:create, :update, :delete] before_filter :authorize, :only => [:create, :update, :delete]
before_filter :check_availability, :only => [:create, :update, :delete] before_filter :check_write_availability, :only => [:create, :update, :delete]
before_filter :check_read_availability, :except => [:create, :update, :delete]
after_filter :compress_output after_filter :compress_output
def create def create

View file

@ -77,8 +77,9 @@ end
# inflect.uncountable %w( fish sheep ) # inflect.uncountable %w( fish sheep )
# end # end
# Set to true to put the API in read-only mode # Set to :readonly to put the API in read-only mode or :offline to
API_READONLY = false # take it completely offline
API_STATUS = :online
# Include your application configuration below # Include your application configuration below
SERVER_URL = ENV['OSM_SERVER_URL'] || 'www.openstreetmap.org' SERVER_URL = ENV['OSM_SERVER_URL'] || 'www.openstreetmap.org'