-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This was done in response to the work to enable continuous deployment for local-links-manager. Given local-links-manager uses Redis on it's own, without sidekiq, similarly to email-alert-frontend, it made sense to move the recently written healthcheck by @1pretz1 to govuk-app-config so it could be used by both applications. Co-authored-by: Peter Hartshorn <[email protected]> Trello: https://trello.com/c/uAx6eKAQ/2276-activate-continuous-deployment-for-local-links-manager
- Loading branch information
1 parent
6839359
commit 59914b6
Showing
4 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
lib/govuk_app_config/govuk_healthcheck/redis_connection.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module GovukHealthcheck | ||
class RedisConnection | ||
def name | ||
:redis_connection | ||
end | ||
|
||
def status | ||
client = Redis.new | ||
|
||
client.set("healthcheck", "val") | ||
client.get("healthcheck") | ||
client.del("healthcheck") | ||
|
||
client.close | ||
|
||
GovukHealthcheck::OK | ||
rescue StandardError | ||
GovukHealthcheck::CRITICAL | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require "spec_helper" | ||
require "govuk_app_config/govuk_healthcheck" | ||
require_relative "shared_interface" | ||
|
||
RSpec.describe GovukHealthcheck::RedisConnection do | ||
let(:redis) { double(:redis) } | ||
let(:redis_client) { double(:redis_client, set: "OK", get: "val", del: 1, close: nil) } | ||
|
||
before do | ||
stub_const("Redis", redis) | ||
allow(redis).to receive(:new).and_return(redis_client) | ||
end | ||
|
||
context "when the database is connected" do | ||
before { allow(redis_client).to receive(:set) } | ||
it_behaves_like "a healthcheck" | ||
it "returns OK" do | ||
expect(redis_client).to receive(:set).with(anything, anything) | ||
expect(subject.status).to eq(GovukHealthcheck::OK) | ||
end | ||
end | ||
|
||
context "when the database is not connected" do | ||
before { allow(redis_client).to receive(:set).with(anything, anything).and_raise("error") } | ||
it_behaves_like "a healthcheck" | ||
it "returns CRITICAL" do | ||
expect(subject.status).to eq(GovukHealthcheck::CRITICAL) | ||
end | ||
end | ||
end |