Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Que integration #305

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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