Skip to content

Commit

Permalink
Add capistrano tasks to take a node off the load balancer. (#291)
Browse files Browse the repository at this point in the history
* Add capistrano tasks to take a node off the load balancer.

Closes #290

* Match CircleCI config to Ruby version
  • Loading branch information
maxkadel authored Nov 15, 2024
1 parent 13129f0 commit 38070f6
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 11 deletions.
10 changes: 6 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
working_directory: ~/orcid_princeton
docker:
- &ruby_docker
image: cimg/ruby:3.2-browsers
image: cimg/ruby:3.2.5-browsers
environment:
RAILS_ENV: test
steps:
Expand All @@ -40,7 +40,8 @@ jobs:
- install_dependencies
- persist_to_workspace:
root: &root '~/orcid_princeton'
paths: '*'
paths:
- '*'

rubocop:
working_directory: *root
Expand All @@ -57,7 +58,7 @@ jobs:
# We don't actually need any of the ruby environment to lint JS... but use what we have for now.
working_directory: ~/orcid_princeton
docker:
- image: cimg/ruby:3.2-browsers
- image: cimg/ruby:3.2.5-browsers
environment:
RAILS_ENV: test
steps:
Expand Down Expand Up @@ -94,7 +95,8 @@ jobs:
command: COVERALLS_REPO_TOKEN=$COVERALLS_REPO_TOKEN bundle exec rspec --format progress
- persist_to_workspace:
root: *root
paths: 'coverage'
paths:
- 'coverage'
- store_artifacts:
path:
/home/circleci/orcid_princeton/tmp/capybara
Expand Down
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ gem "rails", "~> 7.1.0"
gem "bcrypt_pbkdf"
gem "bootsnap", require: false
gem "ed25519"
gem "health-monitor-rails"
# Pinning to 12.4.0 due to Rails 7.1 compatibility issue in 12.4.1
gem "health-monitor-rails", "12.4.0"
gem "honeybadger"
gem "httparty"
gem "isni"
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ GEM
activesupport (>= 6.1)
hashdiff (1.1.1)
hashie (5.0.0)
health-monitor-rails (12.1.0)
health-monitor-rails (12.4.0)
railties (>= 6.1)
honeybadger (5.8.0)
httparty (0.22.0)
Expand Down Expand Up @@ -543,7 +543,7 @@ DEPENDENCIES
ed25519
factory_bot_rails
ffaker
health-monitor-rails
health-monitor-rails (= 12.4.0)
honeybadger
httparty
isni
Expand Down
31 changes: 31 additions & 0 deletions config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,37 @@
# Must match `ViteRuby.config.public_output_dir`, which by default is 'vite'
set :assets_prefix, "vite"

namespace :application do
# You can/ should apply this command to a single host
# cap --hosts=orcid-staging1.princeton.edu staging application:remove_from_nginx
desc "Marks the server(s) to be removed from the loadbalancer"
task :remove_from_nginx do
count = 0
on roles(:app) do
count += 1
end
if count > (roles(:app).length / 2)
raise "You must run this command on no more than half the servers utilizing the --hosts= switch"
end
on roles(:app) do
within release_path do
execute :touch, "public/remove-from-nginx"
end
end
end

# You can/ should apply this command to a single host
# cap --hosts=orcid-staging1.princeton.edu staging application:serve_from_nginx
desc "Marks the server(s) to be added back to the loadbalancer"
task :serve_from_nginx do
on roles(:app) do
within release_path do
execute :rm, "-f public/remove-from-nginx"
end
end
end
end

# Workaround for this issue: https://github.com/capistrano/rails/issues/235
Rake::Task["deploy:assets:backup_manifest"].clear_actions
Rake::Task["deploy:assets:restore_manifest"].clear_actions
Expand Down
12 changes: 8 additions & 4 deletions config/initializers/health_monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
HealthMonitor.configure do |config|
config.cache

config.add_custom_provider(OrcidApiStatus)
config.add_custom_provider(OrcidApiStatus).configure do |provider_config|
# set the orcid API check to not critical
provider_config.critical = false
end

# set the orcid API check to no critical
config.providers.last.configuration.critical = false
config.file_absence.configure do |file_config|
file_config.filename = "public/remove-from-nginx"
end

# Make this health check available at /health
config.path = :health

config.error_callback = proc do |e|
Rails.logger.error "Health check failed with: #{e.message}"
Honeybadger.notify(e)
Honeybadger.notify(e) unless e.is_a? HealthMonitor::Providers::FileAbsenceException
end
end
end
File renamed without changes.

0 comments on commit 38070f6

Please sign in to comment.