-
-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove ActiveJob keys for both Sidekiq and DelayedJob
- Loading branch information
1 parent
729c22f
commit aee5baf
Showing
5 changed files
with
87 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module Raven | ||
module ContextFilter | ||
ACTIVEJOB_RESERVED_PREFIX = "_aj_".freeze | ||
HAS_GLOBALID = const_defined?('GlobalID') | ||
|
||
extend self | ||
|
||
# Once an ActiveJob is queued, ActiveRecord references get serialized into | ||
# some internal reserved keys, such as _aj_globalid. | ||
# | ||
# The problem is, if this job in turn gets queued back into ActiveJob with | ||
# these magic reserved keys, ActiveJob will throw up and error. We want to | ||
# capture these and mutate the keys so we can sanely report it. | ||
def filter(context) | ||
case context | ||
when Array | ||
context.map { |arg| filter(arg) } | ||
when Hash | ||
context.inject({}) do |hash, (key, value)| | ||
next hash if key[0..3] == ACTIVEJOB_RESERVED_PREFIX | ||
hash[key] = filter(value) | ||
hash | ||
end | ||
else | ||
format_globalid(context) | ||
end | ||
end | ||
|
||
private | ||
|
||
def format_globalid(context) | ||
if HAS_GLOBALID && context.is_a?(GlobalID) | ||
context.to_s | ||
else | ||
context | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require "spec_helper" | ||
|
||
require "raven/context_filter" | ||
|
||
RSpec.describe Raven::ContextFilter do | ||
context "filters out ActiveJob keys from context" do | ||
let(:context) do | ||
{ _aj_globalid: GlobalID.new("gid://app/model/id"), key: "value" } | ||
end | ||
let(:expected_context) do | ||
{ key: "value" } | ||
end | ||
|
||
it "removes reserved keys" do | ||
new_context = described_class.filter(context) | ||
|
||
expect(new_context).to eq(expected_context) | ||
end | ||
end | ||
|
||
context "filters out ActiveJob keys from nested context" do | ||
let(:context) do | ||
{ | ||
_aj_globalid: GlobalID.new("gid://app/model/id"), | ||
arguments: { "key" => "value", "_aj_symbol_keys" => ["key"] } | ||
} | ||
end | ||
let(:expected_context) do | ||
{ | ||
arguments: { "key" => "value" } | ||
} | ||
end | ||
|
||
it "removes reserved keys" do | ||
new_context = described_class.filter(context) | ||
|
||
expect(new_context).to eq(expected_context) | ||
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