Skip to content

Instantly share code, notes, and snippets.

@koppen
Last active September 28, 2020 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koppen/a90680cff3655215e34a28aca0d6183a to your computer and use it in GitHub Desktop.
Save koppen/a90680cff3655215e34a28aca0d6183a to your computer and use it in GitHub Desktop.
Delayed::Job helpers
module Delayed::Job::Ext
module_function
# Returns all failed jobs
def failed_jobs
Delayed::Job.where.not(:last_error => nil).order(:failed_at)
end
def failed_with(message)
failed_jobs.
where("last_error LIKE ?", "#{message}%")
end
# Outputs an overview of failed jobs
def failed_overview
failed_jobs.each { |job|
handler = begin
YAML.load(job.handler)
rescue StandardError => error
error
end
p [job.id, handler.class, job.last_error.first(150)]
}
nil
end
# Returns all jobs whose handler partially matches the given handler name
def list_jobs(handler)
Delayed::Job.where("handler LIKE ?", "%#{handler}%")
end
# Schedules job for retry
def retry(job)
job.update_columns(:attempts => job.attempts - 1, :failed_at => nil)
end
end
# frozen_string_literal: true
require "open-uri"
# Get warnings when your job queue is backed up or crashed or otherwise not working.
#
# This job notifies a Honeybadger CheckIn every hour as long as the background queue is running.
class HoneybadgerCheckinJob < ApplicationJob
queue_as :default
def perform
perform_checkin
enqueue_next_checkin
rescue StandardError => error
puts "Something went wrong when doing check in: #{error.inspect}"
end
private
def enqueue_next_checkin
HoneybadgerCheckinJob.set(:wait => 1.hour).perform_later
end
def perform_checkin
open(checkin_url).read
end
def checkin_url
ENV.fetch("HONEYBADGER_CHECK_IN_URL")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment