Last active
September 28, 2020 13:41
-
-
Save koppen/a90680cff3655215e34a28aca0d6183a to your computer and use it in GitHub Desktop.
Delayed::Job helpers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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