Class: MaintenanceSwitch::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/maintenance_switch/base.rb

Constant Summary collapse

MAINTENANCE_CACHE_KEY =
'MAINTENANCE_KEY'
DEFAULT_REASON =
'Scheduled maintenance'

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Base

Returns a new instance of Base.



10
11
12
13
14
# File 'lib/maintenance_switch/base.rb', line 10

def initialize(app, options = {})
  @app = app
  @options = options
  @redis = Redis.new(url: ENV.fetch('MAINTENANCE_REDIS_URL'))
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/maintenance_switch/base.rb', line 16

def call(env)
  if maintenance_on?
    [503, { 'X-MaintenaceReason' => reason }, [
      "Maintenance Mode ON. Reason: #{reason}. Started at: #{started_at}"
    ]]
  else
    @app.call(env)
  end
end