Skip to content

Commit

Permalink
new loadbalancer cap tasks (#860)
Browse files Browse the repository at this point in the history
* pin version of health-monitor

* add two loadbalancer caps

one of the cap tasks removes a service for the loadbalancer and the
other one adds it back to server

---------

Co-authored-by: Max Kadel <[email protected]>
  • Loading branch information
kayiwa and maxkadel authored Nov 13, 2024
1 parent bdbe9cb commit 9591f4a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ gem 'ed25519', '~> 1.3'
gem 'faraday', '~> 2.7'
gem "flipflop", git: "https://github.com/voormedia/flipflop.git", ref: "0d70d8e33483a9c0282ed8d6bca9c5ccd61e61e8"
gem 'foreman'
gem "health-monitor-rails"
gem "health-monitor-rails", "12.4.0"
gem 'honeybadger'
gem 'icalendar'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
Expand Down
5 changes: 3 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ GEM
activesupport (>= 6.1)
hashdiff (1.1.0)
hashie (5.0.0)
health-monitor-rails (12.3.0)
health-monitor-rails (12.4.0)
railties (>= 6.1)
honeybadger (5.13.0)
httparty (0.22.0)
Expand Down Expand Up @@ -546,6 +546,7 @@ PLATFORMS
arm64-darwin-21
arm64-darwin-22
arm64-darwin-23
arm64-darwin-24
x86_64-darwin-21
x86_64-linux

Expand All @@ -572,7 +573,7 @@ DEPENDENCIES
faraday (~> 2.7)
flipflop!
foreman
health-monitor-rails
health-monitor-rails (= 12.4.0)
honeybadger
icalendar
jbuilder (~> 2.5)
Expand Down
27 changes: 27 additions & 0 deletions config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,34 @@

# Default value for :format is :airbrussh.
# set :format, :airbrussh
#
# # You can/ should apply this command to a subset of hosts
# cap --hosts=lib-jobs-staging2.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
raise "You must run this command on individual servers utilizing the --hosts= switch" if count > (roles(:app).length / 2)
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 subset of hosts
# cap --hosts=lib-jobs-staging2.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

before "deploy:reverted", "deploy:assets:precompile"
# You can configure the Airbrussh format using :format_options.
# These are the defaults.
# set :format_options, command_output: true, log_file: "log/capistrano.log", color: :auto, truncate: :auto
Expand Down
6 changes: 5 additions & 1 deletion config/initializers/health_monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
# Make this health check available at /health
config.path = :health

config.file_absence.configure do |file_config|
file_config.filename = "public/remove-from-nginx"
end

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 9591f4a

Please sign in to comment.