Skip to content

Commit

Permalink
Merge pull request #1223 from pulibrary/figgy#6394-tag-maintenance-wi…
Browse files Browse the repository at this point in the history
…ndow

Add Honeybadger downtime hook
  • Loading branch information
tpendragon authored Jul 31, 2024
2 parents c01c155 + b007d97 commit 2410b7c
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 7 deletions.
26 changes: 19 additions & 7 deletions .circleci/config.yml
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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ end

group :test do
gem "axe-core-rspec"
gem "timecop"
gem "webmock"
end

Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ GEM
thor (1.3.1)
thread_safe (0.3.6)
tilt (2.3.0)
timecop (0.9.10)
timeout (0.4.1)
trailblazer-option (0.1.2)
turbolinks (5.2.1)
Expand Down Expand Up @@ -711,6 +712,7 @@ DEPENDENCIES
sneakers
spring
strscan (= 3.0.1)
timecop
turbolinks
twitter-typeahead-rails
vite_rails
Expand Down
24 changes: 24 additions & 0 deletions config/initializers/honeybadger_downtime_hook.rb
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
59 changes: 59 additions & 0 deletions spec/honeybadger_check_spec.rb
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

0 comments on commit 2410b7c

Please sign in to comment.