Skip to content

Commit 84a0bf0

Browse files
committed
Add storage to the deferred context
this is a storage hidden from the tasks that can be used by instrumentation code and middleware to pass data to each other without exposing it to the user
1 parent 5dd7cbe commit 84a0bf0

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

lib/rage/deferred/context.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ def self.build(task, args, kwargs, storage: nil)
1313
args.empty? ? nil : args,
1414
kwargs.empty? ? nil : kwargs,
1515
nil,
16-
request_id
16+
request_id,
17+
storage
1718
]
1819
end
1920

@@ -40,4 +41,8 @@ def self.inc_attempts(context)
4041
def self.get_request_id(context)
4142
context[4]
4243
end
44+
45+
def self.get_storage(context)
46+
context[5]
47+
end
4348
end

spec/deferred/context_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,23 @@
8585
expect(context[3]).to eq(4)
8686
end
8787
end
88+
89+
describe ".get_storage" do
90+
context "with empty storage" do
91+
it "returns the storage object from context" do
92+
context = described_class.build(nil, [], {})
93+
94+
expect(described_class.get_storage(context)).to be_nil
95+
end
96+
end
97+
98+
context "wit non-empty storage" do
99+
it "returns the storage object from context" do
100+
storage = { test: true }
101+
context = described_class.build(nil, [], {}, storage: storage)
102+
103+
expect(described_class.get_storage(context)).to eq(storage)
104+
end
105+
end
106+
end
88107
end

0 commit comments

Comments
 (0)