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

Use thread queue delivery method for Resque, when it's safe to do so #629

Merged
merged 3 commits into from
Aug 18, 2020
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Changelog
* Sidekiq now uses `thread_queue` delivery by default
| [#626](https://github.com/bugsnag/bugsnag-ruby/pull/626)

* Rescue now uses `thread_queue` delivery when `at_exit` hooks are enabled
| [#629](https://github.com/bugsnag/bugsnag-ruby/pull/629)

## 6.16.0 (12 August 2020)

### Enhancements
Expand Down
1 change: 1 addition & 0 deletions features/fixtures/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ services:
- DB_PASSWORD=test_password
- DB_HOST=postgres
- REDIS_URL=redis://redis:6379
- RUN_AT_EXIT_HOOKS
restart: "no"

sidekiq:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
config.api_key = ENV['BUGSNAG_API_KEY']
config.endpoint = ENV['BUGSNAG_ENDPOINT']
config.session_endpoint = ENV['BUGSNAG_ENDPOINT']

config.add_on_error(proc do |report|
report.add_tab(:config, {
delivery_method: config.delivery_method.to_s,
})
end)
end
24 changes: 23 additions & 1 deletion features/rails_features/integrations.feature
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Scenario: Rake
And the event "metaData.rake_task.arguments" is null

@rails_integrations
Scenario: Resque
Scenario: Resque (no on_exit hooks)
When I run "bundle exec rake resque:work" in the rails app
And I run "Resque.enqueue(ResqueWorker)" with the rails runner
And I wait to receive a request
Expand All @@ -82,6 +82,28 @@ Scenario: Resque
And the event "severityReason.attributes.framework" equals "Resque"
And the event "app.type" equals "resque"
And the exception "errorClass" equals "RuntimeError"
And the event "metaData.config.delivery_method" equals "synchronous"
And the event "metaData.context" equals "ResqueWorker@crash"
And the event "metaData.payload.class" equals "ResqueWorker"
And the event "metaData.rake_task.name" equals "resque:work"
And the event "metaData.rake_task.description" equals "Start a Resque worker"
And the event "metaData.rake_task.arguments" is null

@rails_integrations
Scenario: Resque (with on_exit hooks)
Given I set environment variable "RUN_AT_EXIT_HOOKS" to "1"
When I run "bundle exec rake resque:work" in the rails app
And I run "Resque.enqueue(ResqueWorker)" with the rails runner
And I wait to receive a request
Then the request is valid for the error reporting API version "4.0" for the "Ruby Bugsnag Notifier"
And the event "unhandled" is true
And the event "context" equals "ResqueWorker@crash"
And the event "severity" equals "error"
And the event "severityReason.type" equals "unhandledExceptionMiddleware"
And the event "severityReason.attributes.framework" equals "Resque"
And the event "app.type" equals "resque"
And the exception "errorClass" equals "RuntimeError"
And the event "metaData.config.delivery_method" equals "thread_queue"
And the event "metaData.context" equals "ResqueWorker@crash"
And the event "metaData.payload.class" equals "ResqueWorker"
And the event "metaData.rake_task.name" equals "resque:work"
Expand Down
13 changes: 10 additions & 3 deletions lib/bugsnag/integrations/resque.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,23 @@ def save
# Auto-load the failure backend
Bugsnag::Resque.add_failure_backend

if Resque::Worker.new(:bugsnag_fork_check).fork_per_job?
worker = Resque::Worker.new(:bugsnag_fork_check)

# If at_exit hooks are not enabled then we can't use the thread queue delivery
# method because it relies on an at_exit hook to ensure the queue is flushed
can_use_thread_queue = worker.respond_to?(:run_at_exit_hooks) && worker.run_at_exit_hooks
default_delivery_method = can_use_thread_queue ? :thread_queue : :synchronous

if worker.fork_per_job?
Resque.after_fork do
Bugsnag.configuration.detected_app_type = "resque"
Bugsnag.configuration.default_delivery_method = :synchronous
Bugsnag.configuration.default_delivery_method = default_delivery_method
Bugsnag.configuration.runtime_versions["resque"] = ::Resque::VERSION
end
else
Resque.before_first_fork do
Bugsnag.configuration.detected_app_type = "resque"
Bugsnag.configuration.default_delivery_method = :synchronous
Bugsnag.configuration.default_delivery_method = default_delivery_method
Bugsnag.configuration.runtime_versions["resque"] = ::Resque::VERSION
end
end