Skip to content

Commit

Permalink
Add Que integration
Browse files Browse the repository at this point in the history
  • Loading branch information
s-andringa committed Jul 1, 2016
1 parent d1445b1 commit 7ff18aa
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/bugsnag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def after_notify_callbacks
end
end

[:resque, :sidekiq, :mailman, :delayed_job].each do |integration|
[:resque, :sidekiq, :mailman, :delayed_job, :que].each do |integration|
begin
require "bugsnag/#{integration}"
rescue LoadError
Expand Down
31 changes: 31 additions & 0 deletions lib/bugsnag/que.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
if defined?(::Que)
Que.error_handler = proc do |error, job|
begin
job = job.dup # Make sure the original job object is not mutated.

Bugsnag.configuration.app_type = "que"

Bugsnag.auto_notify(error) do |notification|
job[:error_count] += 1

# If the job was scheduled using ActiveJob then unwrap the job details for clarity:
if job[:job_class] == "ActiveJob::QueueAdapters::QueAdapter::JobWrapper"
wrapped_job = job[:args].last
wrapped_job = wrapped_job.each_with_object({}) { |(k, v), result| result[k.to_sym] = v } # Symbolize keys

# Align key names with keys in `job`
wrapped_job[:queue] = wrapped_job.delete(:queue_name)
wrapped_job[:args] = wrapped_job.delete(:arguments)

job.merge!(wrapper_job_class: job[:job_class], wrapper_job_id: job[:job_id]).merge!(wrapped_job)
end

notification.add_tab(:job, job)
end
rescue => e
# Que supresses errors raised by its error handler to avoid killing the worker. Log them somewhere:
Bugsnag.warn("Failed to notify Bugsnag of error in Que job (#{e.class}): #{e.message} \n#{e.backtrace[0..9].join("\n")}")
raise
end
end
end

0 comments on commit 7ff18aa

Please sign in to comment.