Skip to content

Instantly share code, notes, and snippets.

@ssaunier
Last active July 17, 2018 01:26
Show Gist options
  • Select an option

  • Save ssaunier/e2d488bb931b5dc8df0f329c652eac25 to your computer and use it in GitHub Desktop.

Select an option

Save ssaunier/e2d488bb931b5dc8df0f329c652eac25 to your computer and use it in GitHub Desktop.
Add healthchecks.io to your Rails / Sidekiq project

Depends on the sidekiq-cron gem.

curl https://gist.githubusercontent.com/ssaunier/e2d488bb931b5dc8df0f329c652eac25/raw/health_check_job.rb > app/jobs/health_check_job.rb

You need to set HEALTH_CHECK_URL in the prod ENV.

class HealthCheckJob < ActiveJob::Base
queue_as :default
def perform
require 'net/http'
if ENV['HEALTH_CHECK_URL'].present?
Net::HTTP.get(URI(ENV['HEALTH_CHECK_URL']))
else
Rails.logger.warn("Cannot report good health. No HEALTH_CHECK_URL found in ENV.")
end
end
end
Sidekiq::Cron::Job.create(
name: 'Notify healthchecks.io that a sidekiq worker is running',
cron: '*/5 * * * *',
klass: 'HealthCheckJob')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment