Merge pull request #5283 from betagouv/add_maintenance_to_ping
Ajoute un mode maintenance (404) a l'url de ping
This commit is contained in:
commit
9cb2510b29
2 changed files with 18 additions and 3 deletions
|
@ -1,11 +1,16 @@
|
||||||
class PingController < ApplicationController
|
class PingController < ApplicationController
|
||||||
def index
|
def index
|
||||||
Rails.logger.silence do
|
Rails.logger.silence do
|
||||||
if (ActiveRecord::Base.connected?)
|
status_code = if File.file?(Rails.root.join("maintenance"))
|
||||||
head :ok, content_type: "application/json"
|
# See https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#4.2-http-check%20disable-on-404
|
||||||
|
:not_found
|
||||||
|
elsif (ActiveRecord::Base.connected?)
|
||||||
|
:ok
|
||||||
else
|
else
|
||||||
head :internal_server_error, content_type: "application/json"
|
:internal_server_error
|
||||||
end
|
end
|
||||||
|
|
||||||
|
head status_code, content_type: "application/json"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,5 +11,15 @@ describe PingController, type: :controller do
|
||||||
|
|
||||||
it { expect(subject.status).to eq 500 }
|
it { expect(subject.status).to eq 500 }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when a maintenance file is present' do
|
||||||
|
before do
|
||||||
|
allow(File).to receive(:file?).and_return(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'tells HAProxy that the app is in maintenance, but will be available again soon' do
|
||||||
|
expect(subject.status).to eq 404
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue