-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/DEX-2166/query-logs-contexts' into 'master'
[DEX-2166] feat: Add ContextItemProcessMiddleware for execution context tracking Closes DEX-2166 See merge request nstmrt/rubygems/outbox!100
- Loading branch information
Showing
7 changed files
with
63 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
if ActiveRecord.version >= Gem::Version.new("7.0.0") | ||
Rails.application.config.active_record.tap do |config| | ||
config.query_log_tags << { | ||
box_name: ->(context) { context[:box_item]&.class&.box_name }, | ||
box_item_id: ->(context) { context[:box_item]&.uuid } | ||
} | ||
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
19 changes: 19 additions & 0 deletions
19
lib/sbmt/outbox/middleware/execution_context/context_item_process_middleware.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,19 @@ | ||
# frozen_string_literal: true | ||
|
||
require "sbmt/outbox/middleware/execution_context/context_item_process_middleware" | ||
|
||
module Sbmt | ||
module Outbox | ||
module Middleware | ||
module ExecutionContext | ||
class ContextItemProcessMiddleware | ||
def call(item) | ||
ActiveSupport::ExecutionContext[:box_item] = item | ||
|
||
yield | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
|
||
module Sbmt | ||
module Outbox | ||
VERSION = "6.7.0" | ||
VERSION = "6.8.0" | ||
end | ||
end |
16 changes: 16 additions & 0 deletions
16
spec/lib/sbmt/outbox/middleware/execution_context/context_item_process_middleware_spec.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,16 @@ | ||
# frozen_string_literal: true | ||
|
||
require "sbmt/outbox/middleware/execution_context/context_item_process_middleware" | ||
|
||
describe Sbmt::Outbox::Middleware::ExecutionContext::ContextItemProcessMiddleware do | ||
let(:outbox_item) { create(:outbox_item) } | ||
|
||
before do | ||
skip("not supported in the current Rails version") unless defined?(ActiveSupport::ExecutionContext) | ||
end | ||
|
||
it "sets execution context" do | ||
described_class.new.call(outbox_item) {} | ||
expect(ActiveSupport::ExecutionContext.to_h[:box_item]).to eq outbox_item | ||
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