-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #670 from bugsnag/active-job-support
Add support for Active Job
- Loading branch information
Showing
21 changed files
with
402 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
15 changes: 15 additions & 0 deletions
15
features/fixtures/rails4/app/app/controllers/active_job_controller.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class ActiveJobController < ActionController::Base | ||
protect_from_forgery | ||
|
||
def handled | ||
NotifyJob.perform_later(1, "hello", { a: "a", b: "b" }, keyword: true) | ||
|
||
render json: {} | ||
end | ||
|
||
def unhandled | ||
UnhandledJob.perform_later(123, { abc: "xyz" }, "abcxyz") | ||
|
||
render json: {} | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
class NotifyJob < ApplicationJob | ||
def perform | ||
def perform(*args, **kwargs) | ||
Bugsnag.notify("Failed") | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Rails 4 doesn't automatically retry jobs, so this is a quick hack to allow us | ||
# to run the same Rails 5/6 tests against Rails 4 by allowing one retry | ||
$attempts = 0 | ||
|
||
class UnhandledJob < ApplicationJob | ||
rescue_from(RuntimeError) do |exception| | ||
raise exception if $attempts >= 2 | ||
|
||
retry_job | ||
end | ||
|
||
def perform(*args, **kwargs) | ||
$attempts += 1 | ||
|
||
raise 'Oh no!' | ||
end | ||
end |
This file contains 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
15 changes: 15 additions & 0 deletions
15
features/fixtures/rails5/app/app/controllers/active_job_controller.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class ActiveJobController < ActionController::Base | ||
protect_from_forgery | ||
|
||
def handled | ||
NotifyJob.perform_later(1, "hello", { a: "a", b: "b" }, keyword: true) | ||
|
||
render json: {} | ||
end | ||
|
||
def unhandled | ||
UnhandledJob.perform_later(123, { abc: "xyz" }, "abcxyz") | ||
|
||
render json: {} | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
class NotifyJob < ApplicationJob | ||
def perform | ||
def perform(*args, **kwargs) | ||
Bugsnag.notify("Failed") | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class UnhandledJob < ApplicationJob | ||
retry_on RuntimeError, wait: 1.second, attempts: 2 | ||
|
||
def perform(*args, **kwargs) | ||
raise 'Oh no!' | ||
end | ||
end |
This file contains 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
15 changes: 15 additions & 0 deletions
15
features/fixtures/rails6/app/app/controllers/active_job_controller.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class ActiveJobController < ActionController::Base | ||
protect_from_forgery | ||
|
||
def handled | ||
NotifyJob.perform_later(1, "hello", { a: "a", b: "b" }, keyword: true) | ||
|
||
render json: {} | ||
end | ||
|
||
def unhandled | ||
UnhandledJob.perform_later(123, { abc: "xyz" }, "abcxyz") | ||
|
||
render json: {} | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
class NotifyJob < ApplicationJob | ||
def perform | ||
def perform(*args, **kwargs) | ||
Bugsnag.notify("Failed") | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class UnhandledJob < ApplicationJob | ||
retry_on RuntimeError, wait: 1.second, attempts: 2 | ||
|
||
def perform(*args, **kwargs) | ||
raise 'Oh no!' | ||
end | ||
end |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
Feature: Active Job | ||
|
||
@rails4 @rails5 @rails6 | ||
Scenario: A handled error will be delivered | ||
Given I start the rails service | ||
When I navigate to the route "/active_job/handled" on the rails app | ||
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 false | ||
And the event "severity" equals "warning" | ||
And the event "context" equals "NotifyJob@default" | ||
And the event "app.type" equals "active job" | ||
And the exception "errorClass" equals "RuntimeError" | ||
And the exception "message" equals "Failed" | ||
And the event "metaData.active_job.job_id" matches "^[0-9a-f-]{36}$" | ||
And the event "metaData.active_job.job_name" equals "NotifyJob" | ||
And the event "metaData.active_job.queue" equals "default" | ||
And the event "metaData.active_job.locale" equals "en" | ||
And the event "metaData.active_job.arguments.0" equals 1 | ||
And the event "metaData.active_job.arguments.1" equals "hello" | ||
And the event "metaData.active_job.arguments.2.a" equals "a" | ||
And the event "metaData.active_job.arguments.2.b" equals "b" | ||
And the event "metaData.active_job.arguments.3.keyword" is true | ||
And in Rails versions ">=" 5 the event "metaData.active_job.provider_job_id" matches "^[0-9a-f-]{36}$" | ||
And in Rails versions ">=" 5 the event "metaData.active_job.executions" equals 1 | ||
And in Rails versions ">=" 6 the event "metaData.active_job.timezone" equals "UTC" | ||
And in Rails versions ">=" 6 the event "metaData.active_job.enqueued_at" is a timestamp | ||
|
||
@rails4 @rails5 @rails6 | ||
Scenario: An unhandled error will be delivered | ||
Given I start the rails service | ||
When I navigate to the route "/active_job/unhandled" on the rails app | ||
And I wait to receive 2 requests | ||
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 "severity" equals "error" | ||
And the event "context" equals "UnhandledJob@default" | ||
And the event "app.type" equals "active job" | ||
And the event "severityReason.type" equals "unhandledExceptionMiddleware" | ||
And the event "severityReason.attributes.framework" equals "Active Job" | ||
And the exception "errorClass" equals "RuntimeError" | ||
And the exception "message" equals "Oh no!" | ||
And the event "metaData.active_job.job_id" matches "^[0-9a-f-]{36}$" | ||
And the event "metaData.active_job.job_name" equals "UnhandledJob" | ||
And the event "metaData.active_job.queue" equals "default" | ||
And the event "metaData.active_job.locale" equals "en" | ||
And the event "metaData.active_job.arguments.0" equals 123 | ||
And the event "metaData.active_job.arguments.1.abc" equals "xyz" | ||
And the event "metaData.active_job.arguments.2" equals "abcxyz" | ||
And in Rails versions ">=" 5 the event "metaData.active_job.provider_job_id" matches "^[0-9a-f-]{36}$" | ||
And in Rails versions ">=" 5 the event "metaData.active_job.executions" equals 1 | ||
And in Rails versions ">=" 6 the event "metaData.active_job.timezone" equals "UTC" | ||
And in Rails versions ">=" 6 the event "metaData.active_job.enqueued_at" is a timestamp | ||
When I discard the oldest 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 "severity" equals "error" | ||
And the event "context" equals "UnhandledJob@default" | ||
And the event "app.type" equals "active job" | ||
And the event "severityReason.type" equals "unhandledExceptionMiddleware" | ||
And the event "severityReason.attributes.framework" equals "Active Job" | ||
And the exception "errorClass" equals "RuntimeError" | ||
And the exception "message" equals "Oh no!" | ||
And the event "metaData.active_job.job_id" matches "^[0-9a-f-]{36}$" | ||
And the event "metaData.active_job.job_name" equals "UnhandledJob" | ||
And the event "metaData.active_job.queue" equals "default" | ||
And the event "metaData.active_job.locale" equals "en" | ||
And the event "metaData.active_job.arguments.0" equals 123 | ||
And the event "metaData.active_job.arguments.1.abc" equals "xyz" | ||
And the event "metaData.active_job.arguments.2" equals "abcxyz" | ||
And in Rails versions ">=" 5 the event "metaData.active_job.provider_job_id" matches "^[0-9a-f-]{36}$" | ||
And in Rails versions ">=" 5 the event "metaData.active_job.executions" equals 2 | ||
And in Rails versions ">=" 6 the event "metaData.active_job.timezone" equals "UTC" | ||
And in Rails versions ">=" 6 the event "metaData.active_job.enqueued_at" is a timestamp |
This file contains 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
Oops, something went wrong.