-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1223 from pulibrary/figgy#6394-tag-maintenance-wi…
…ndow Add Honeybadger downtime hook
- Loading branch information
Showing
5 changed files
with
105 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
--- | ||
version: 2.1 | ||
orbs: | ||
browser-tools: circleci/[email protected].4 | ||
browser-tools: circleci/[email protected].8 | ||
node: circleci/[email protected] | ||
jobs: | ||
build: | ||
|
@@ -20,9 +20,13 @@ jobs: | |
POSTGRES_HOST_AUTH_METHOD: trust | ||
steps: | ||
- run: sudo apt-get update | ||
- browser-tools/install-chrome: | ||
chrome-version: 116.0.5845.96 | ||
- browser-tools/install-chrome | ||
- browser-tools/install-chromedriver | ||
- run: | ||
command: | | ||
google-chrome --version | ||
chromedriver --version | ||
name: Check install | ||
- checkout | ||
- restore_cache: | ||
keys: | ||
|
@@ -72,9 +76,13 @@ jobs: | |
- image: redis:7 | ||
steps: | ||
- run: sudo apt-get update | ||
- browser-tools/install-chrome: | ||
chrome-version: 116.0.5845.96 | ||
- browser-tools/install-chrome | ||
- browser-tools/install-chromedriver | ||
- run: | ||
command: | | ||
google-chrome --version | ||
chromedriver --version | ||
name: Check install | ||
- attach_workspace: | ||
at: '~/pulmap' | ||
# Install Bundler | ||
|
@@ -108,9 +116,13 @@ jobs: | |
PULMAP_DB_USERNAME: geoblacklight | ||
steps: | ||
- run: sudo apt-get update | ||
- browser-tools/install-chrome: | ||
chrome-version: 116.0.5845.96 | ||
- browser-tools/install-chrome | ||
- browser-tools/install-chromedriver | ||
- run: | ||
command: | | ||
google-chrome --version | ||
chromedriver --version | ||
name: Check install | ||
- attach_workspace: | ||
at: '~/pulmap' | ||
- node/install: | ||
|
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 |
---|---|---|
|
@@ -71,6 +71,7 @@ end | |
|
||
group :test do | ||
gem "axe-core-rspec" | ||
gem "timecop" | ||
gem "webmock" | ||
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
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,24 @@ | ||
# frozen_string_literal: true | ||
|
||
# We have a maintenance window every Monday for Staging and Tuesday for | ||
# production, from 5:30 AM to 8:30 AM. | ||
class HoneybadgerCheck | ||
def self.maintenance_window? | ||
return false unless Rails.env.staging? || Rails.env.production? | ||
# Check in Eastern time. | ||
Time.use_zone("America/New_York") do | ||
current_time = Time.zone.now | ||
# Only check times if we're the correct day of the week. | ||
return false if Rails.env.staging? && !current_time.monday? | ||
return false if Rails.env.production? && !current_time.tuesday? | ||
current_time.between?(Time.zone.parse("5:30"), Time.zone.parse("8:30")) | ||
end | ||
end | ||
end | ||
Honeybadger.configure do |config| | ||
config.before_notify do |notice| | ||
# Add a maintenance_window tag - tags seems to be a comma delimited string, | ||
# so split them, add the maintenance_window one, and rejoin them. | ||
notice.context[:maintenance_window] = "true" if HoneybadgerCheck.maintenance_window? | ||
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,59 @@ | ||
# frozen_string_literal: true | ||
require "rails_helper" | ||
|
||
RSpec.describe HoneybadgerCheck do | ||
describe ".maintenance_window?" do | ||
context "when it's staging" do | ||
context "and in the maintenance window" do | ||
it "returns true" do | ||
allow(Rails.env).to receive(:staging?).and_return(true) | ||
Timecop.freeze("2024-07-08 5:40 AM EDT -04:00") do | ||
expect(described_class.maintenance_window?).to eq true | ||
end | ||
end | ||
end | ||
context "in the wrong day" do | ||
it "returns false" do | ||
allow(Rails.env).to receive(:staging?).and_return(true) | ||
Timecop.freeze("2024-07-09 5:40 AM EDT -04:00") do | ||
expect(described_class.maintenance_window?).to eq false | ||
end | ||
end | ||
end | ||
context "in the wrong time" do | ||
it "returns false" do | ||
allow(Rails.env).to receive(:staging?).and_return(true) | ||
Timecop.freeze("2024-07-08 5:00 AM EDT -04:00") do | ||
expect(described_class.maintenance_window?).to eq false | ||
end | ||
end | ||
end | ||
end | ||
context "when it's production" do | ||
context "and in the maintenance window" do | ||
it "returns true" do | ||
allow(Rails.env).to receive(:production?).and_return(true) | ||
Timecop.freeze("2024-07-09 5:40 AM EDT -04:00") do | ||
expect(described_class.maintenance_window?).to eq true | ||
end | ||
end | ||
end | ||
context "in the wrong day" do | ||
it "returns false" do | ||
allow(Rails.env).to receive(:production?).and_return(true) | ||
Timecop.freeze("2024-07-08 5:40 AM EDT -04:00") do | ||
expect(described_class.maintenance_window?).to eq false | ||
end | ||
end | ||
end | ||
context "in the wrong time" do | ||
it "returns false" do | ||
allow(Rails.env).to receive(:production?).and_return(true) | ||
Timecop.freeze("2024-07-09 5:00 AM EDT -04:00") do | ||
expect(described_class.maintenance_window?).to eq false | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |