Skip to content

Instantly share code, notes, and snippets.

@metaskills
Last active July 17, 2019 01:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metaskills/9985360 to your computer and use it in GitHub Desktop.
Save metaskills/9985360 to your computer and use it in GitHub Desktop.
Delayed::Job & Rollbar Integration Notes - https://github.com/rollbar/rollbar-gem/issues/104

About

All output is from the delayed job worker session using the code above.

With Delayed::Plugins::Rollbar

Delayed::Job.enqueue Jobs::Test.new(raise: true, report_exception: false)
`Rollbar.report_exception` was run.
[Worker(host:station.local pid:75372)] Jobs::Test failed with RuntimeError: 💩 - 0 failed attempts
[Worker(host:station.local pid:75372)] `Delayed::Plugins::RollbarTest`: around(:error)
[Worker(host:station.local pid:75372)] `Delayed::Plugins::RollbarTest`: after(:error)
[Worker(host:station.local pid:75372)] 1 jobs processed at 2.4712 j/s, 1 failed ...
Delayed::Job.enqueue Jobs::Test.new(raise: true, report_exception: true)
`Rollbar.report_exception` was run.
`Rollbar.report_exception` was run.
[Worker(host:station.local pid:75372)] Jobs::Test failed with RuntimeError: 💩 - 0 failed attempts
[Worker(host:station.local pid:75372)] `Delayed::Plugins::RollbarTest`: around(:error)
[Worker(host:station.local pid:75372)] `Delayed::Plugins::RollbarTest`: after(:error)
[Worker(host:station.local pid:75372)] 1 jobs processed at 1.5048 j/s, 1 failed ...

No Delayed::Plugins::Rollbar Plugin

Removed by adding Delayed::Worker.plugins.delete(Delayed::Plugins::Rollbar) after the Rollbar.configure block.

Delayed::Job.enqueue Jobs::Test.new(raise: true, report_exception: false)
[Worker(host:station.local pid:74421)] Jobs::Test failed with RuntimeError: 💩 - 0 failed attempts
[Worker(host:station.local pid:74421)] `Delayed::Plugins::RollbarTest`: around(:error)
[Worker(host:station.local pid:74421)] `Delayed::Plugins::RollbarTest`: after(:error)
[Worker(host:station.local pid:74421)] 1 jobs processed at 15.2446 j/s, 1 failed ...
Delayed::Job.enqueue Jobs::Test.new(raise: true, report_exception: true)
`Rollbar.report_exception` was run.
[Worker(host:station.local pid:75037)] Jobs::Test failed with RuntimeError: 💩 - 0 failed attempts
[Worker(host:station.local pid:75037)] `Delayed::Plugins::RollbarTest`: around(:error)
[Worker(host:station.local pid:75037)] `Delayed::Plugins::RollbarTest`: after(:error)
[Worker(host:station.local pid:75037)] 1 jobs processed at 2.2982 j/s, 1 failed ...
# Freedom patch Rollbar so we can see when exceptions are
# being reported in the delayed job log.
module Rollbar
class << self
def report_exception_with_dj_logging(*args)
report_exception_without_dj_logging(*args)
puts '`Rollbar.report_exception` was run.'
end
alias_method_chain :report_exception, :dj_logging
end
end
# This plugin tests the affects of the attached `test_job.rb`
# runnig to see how lifecycle callbacks possible coordinate
# with custom job hooks.
module Delayed
module Plugins
class RollbarTest < Plugin
callbacks do |lifecycle|
lifecycle.around(:error) do |worker, &block|
begin
block.call(worker)
ensure
worker.say '`Delayed::Plugins::RollbarTest`: around(:error)', Logger::DEBUG
end
end
lifecycle.around(:failure) do |worker, &block|
begin
block.call(worker)
ensure
worker.say '`Delayed::Plugins::RollbarTest`: around(:failure)', Logger::DEBUG
end
end
lifecycle.after(:error) do |worker, job|
worker.say '`Delayed::Plugins::RollbarTest`: after(:error)', Logger::DEBUG
end
lifecycle.after(:failure) do |worker, job|
worker.say '`Delayed::Plugins::RollbarTest`: after(:failure)', Logger::DEBUG
end
end
end
end
end
Delayed::Worker.plugins << Delayed::Plugins::RollbarTest
# encoding: UTF-8
# A simple job class that allows us to test exceptions
# and job error hooks.
module Jobs
class Test
def initialize(options={})
@options = options
end
def perform
raise '💩' if @options[:raise]
end
def error(job, exception)
Rollbar.report_exception(exception) if @options[:report_exception]
end
end
end
@metaskills
Copy link
Author

I forgot to mention that failure is only run after a batch of jobs where one of many could have failed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment