mirror of
https://github.com/astuto/astuto.git
synced 2025-12-15 11:17:49 +01:00
Add healthcheck endpoint and task (#230)
This commit is contained in:
committed by
GitHub
parent
fbaed7f44e
commit
1af8687a22
@@ -56,4 +56,10 @@ Rails.application.routes.draw do
|
|||||||
get 'authentication'
|
get 'authentication'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Healthcheck endpoint
|
||||||
|
get '/health', to: proc {
|
||||||
|
Tenant.first # to make sure db works
|
||||||
|
[200, {}, ['success']]
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|||||||
20
lib/tasks/healthcheck.rake
Normal file
20
lib/tasks/healthcheck.rake
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
require 'rake'
|
||||||
|
require 'net/http'
|
||||||
|
require 'uri'
|
||||||
|
|
||||||
|
task :healthcheck, [:port] do |t, args|
|
||||||
|
port = args[:port] || 3000
|
||||||
|
|
||||||
|
# Make the HTTP request to the health endpoint
|
||||||
|
uri = URI.parse("http://localhost:#{port}/health")
|
||||||
|
response = Net::HTTP.get_response(uri)
|
||||||
|
|
||||||
|
exit_code = response.is_a?(Net::HTTPSuccess) ? 0 : 1
|
||||||
|
|
||||||
|
rescue
|
||||||
|
exit_code = 1
|
||||||
|
|
||||||
|
ensure
|
||||||
|
puts "Healthcheck returned: #{exit_code.to_s}"
|
||||||
|
exit(exit_code)
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user