Allow the API to be taken offline completely as well as being put into
readonly mode,
This commit is contained in:
parent
27d8f2ef63
commit
9c01c4cb63
11 changed files with 25 additions and 9 deletions
|
@ -2,7 +2,7 @@ class AmfController < ApplicationController
|
|||
require 'stringio'
|
||||
|
||||
session :off
|
||||
before_filter :check_availability
|
||||
before_filter :check_write_availability
|
||||
|
||||
# to log:
|
||||
# RAILS_DEFAULT_LOGGER.error("Args: #{args[0]}, #{args[1]}, #{args[2]}, #{args[3]}")
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
class ApiController < ApplicationController
|
||||
|
||||
session :off
|
||||
before_filter :check_read_availability, :except => [:capabilities]
|
||||
after_filter :compress_output
|
||||
|
||||
#COUNT is the number of map requests to allow before exiting and starting a new process
|
||||
|
|
|
@ -39,8 +39,16 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
end
|
||||
|
||||
def check_availability
|
||||
if API_READONLY
|
||||
def check_read_availability
|
||||
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"
|
||||
render :nothing => true, :status => :service_unavailable
|
||||
return false
|
||||
|
|
|
@ -3,7 +3,8 @@ class NodeController < ApplicationController
|
|||
|
||||
session :off
|
||||
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
|
||||
|
||||
def create
|
||||
|
|
|
@ -2,6 +2,7 @@ class OldNodeController < ApplicationController
|
|||
require 'xml/libxml'
|
||||
|
||||
session :off
|
||||
before_filter :check_read_availability
|
||||
after_filter :compress_output
|
||||
|
||||
def history
|
||||
|
|
|
@ -2,6 +2,7 @@ class OldSegmentController < ApplicationController
|
|||
require 'xml/libxml'
|
||||
|
||||
session :off
|
||||
before_filter :check_read_availability
|
||||
after_filter :compress_output
|
||||
|
||||
def history
|
||||
|
|
|
@ -2,6 +2,7 @@ class OldWayController < ApplicationController
|
|||
require 'xml/libxml'
|
||||
|
||||
session :off
|
||||
before_filter :check_read_availability
|
||||
after_filter :compress_output
|
||||
|
||||
def history
|
||||
|
|
|
@ -3,7 +3,8 @@ class SegmentController < ApplicationController
|
|||
|
||||
session :off
|
||||
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
|
||||
|
||||
def create
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class SwfController < ApplicationController
|
||||
session :off
|
||||
before_filter :check_availability
|
||||
before_filter :check_read_availability
|
||||
|
||||
# to log:
|
||||
# RAILS_DEFAULT_LOGGER.error("Args: #{args[0]}, #{args[1]}, #{args[2]}, #{args[3]}")
|
||||
|
|
|
@ -3,7 +3,8 @@ class WayController < ApplicationController
|
|||
|
||||
session :off
|
||||
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
|
||||
|
||||
def create
|
||||
|
|
|
@ -77,8 +77,9 @@ end
|
|||
# inflect.uncountable %w( fish sheep )
|
||||
# end
|
||||
|
||||
# Set to true to put the API in read-only mode
|
||||
API_READONLY = false
|
||||
# Set to :readonly to put the API in read-only mode or :offline to
|
||||
# take it completely offline
|
||||
API_STATUS = :online
|
||||
|
||||
# Include your application configuration below
|
||||
SERVER_URL = ENV['OSM_SERVER_URL'] || 'www.openstreetmap.org'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue