-
-
Notifications
You must be signed in to change notification settings - Fork 207
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 #79 from bensheldon/error_tracking
Capture errors via instrumentation from retry_on and discard_on
- Loading branch information
Showing
9 changed files
with
176 additions
and
9 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
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,25 @@ | ||
module GoodJob | ||
# Thread-local attributes for passing values from Instrumentation. | ||
# (Cannot use ActiveSupport::CurrentAttributes because ActiveJob resets it) | ||
|
||
module CurrentExecution | ||
# @!attribute [rw] error_on_retry | ||
# @!scope class | ||
# Error captured by retry_on | ||
# @return [Exception, nil] | ||
thread_mattr_accessor :error_on_retry | ||
|
||
# @!attribute [rw] error_on_discard | ||
# @!scope class | ||
# Error captured by discard_on | ||
# @return [Exception, nil] | ||
thread_mattr_accessor :error_on_discard | ||
|
||
# Resets attributes | ||
# @return [void] | ||
def self.reset | ||
self.error_on_retry = nil | ||
self.error_on_discard = nil | ||
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe GoodJob::CurrentExecution do | ||
describe '.error_on_discard' do | ||
it 'maintains value across threads' do | ||
described_class.error_on_discard = 'apple' | ||
|
||
Thread.new do | ||
described_class.error_on_discard = 'bear' | ||
end.join | ||
|
||
expect(described_class.error_on_discard).to eq 'apple' | ||
end | ||
|
||
it 'maintains value across Rails execution wrapper' do | ||
Rails.application.executor.wrap do | ||
described_class.error_on_discard = 'apple' | ||
end | ||
|
||
expect(described_class.error_on_discard).to eq 'apple' | ||
end | ||
|
||
it 'is resettable' do | ||
described_class.error_on_discard = 'apple' | ||
described_class.reset | ||
expect(described_class.error_on_discard).to eq nil | ||
end | ||
end | ||
|
||
describe '.error_on_retry' do | ||
it 'maintains value across threads' do | ||
described_class.error_on_retry = 'apple' | ||
|
||
Thread.new do | ||
described_class.error_on_retry = 'bear' | ||
end.join | ||
|
||
expect(described_class.error_on_retry).to eq 'apple' | ||
end | ||
|
||
it 'maintains value across Rails execution wrapper' do | ||
Rails.application.executor.wrap do | ||
described_class.error_on_retry = 'apple' | ||
end | ||
|
||
expect(described_class.error_on_retry).to eq 'apple' | ||
end | ||
|
||
it 'is resettable' do | ||
described_class.error_on_retry = 'apple' | ||
described_class.reset | ||
expect(described_class.error_on_retry).to eq nil | ||
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