Skip to content

Instantly share code, notes, and snippets.

@jnunemaker
Created September 28, 2023 14:31
Show Gist options
  • Save jnunemaker/d418d266ceba958bb637367970ee20ee to your computer and use it in GitHub Desktop.
Save jnunemaker/d418d266ceba958bb637367970ee20ee to your computer and use it in GitHub Desktop.
Automatic honey badger check ins for active job. Just setup the check in with honey badger and configure an env var to the identifier they provide.
# Set HONEYBADGER_FOO_BAR_JOB=asdf where asdf is the check in value Honeybadger gives you.
class ApplicationJob < ActiveJob::Base
after_perform { |job| job.honeybadger_checkin }
# Check in with Honeybadger to let us know that the job was performed
# if there is an identifier configured for the job.
def honeybadger_checkin
identifier = honeybadger_checkin_identifier
return unless identifier.present?
Honeybadger.check_in(identifier)
end
# Turns Foo::BarJob into HONEYBADGER_FOO_BAR_JOB.
def honeybadger_checkin_name
"HONEYBADGER_#{self.class.name.underscore.parameterize(separator: "_".freeze).upcase}"
end
# Get the identifier value from ENV based on name.
def honeybadger_checkin_identifier
ENV[honeybadger_checkin_name]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment