Skip to content

Commit

Permalink
Add capistrano tasks to take a node off the load balancer.
Browse files Browse the repository at this point in the history
Closes #2546
  • Loading branch information
maxkadel committed Nov 13, 2024
1 parent f9745a6 commit 9b86e5d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ gem 'faraday_middleware', '~> 1.0'
gem 'ffi', '>= 1.9.25'
gem 'friendly_id'
gem 'gyoku', '~> 1.0'
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 'high_voltage', '~> 3.0'
gem 'honeybadger'
gem 'human_languages', '~> 0.7'
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ GEM
rexml (~> 3.0)
hashdiff (1.1.1)
hashie (5.0.0)
health-monitor-rails (12.1.0)
health-monitor-rails (12.4.0)
railties (>= 6.1)
high_voltage (3.1.2)
honeybadger (5.4.1)
Expand Down Expand Up @@ -701,7 +701,7 @@ DEPENDENCIES
ffi (>= 1.9.25)
friendly_id
gyoku (~> 1.0)
health-monitor-rails
health-monitor-rails (= 12.4.0)
high_voltage (~> 3.0)
honeybadger
human_languages (~> 0.7)
Expand Down
31 changes: 31 additions & 0 deletions config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,37 @@
end
end

namespace :application do
# You can/ should apply this command to a single host
# cap --hosts=bibdata-staging1.lib.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=bibdata-staging1.lib.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

after 'deploy:reverted', 'sidekiq:restart'
after 'deploy:published', 'sidekiq:restart'
after 'deploy:restart', 'sqs_poller:restart'
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/health_monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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

0 comments on commit 9b86e5d

Please sign in to comment.