Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT: extract ciruit_options when using public call interface #65

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/trailblazer/operation/public_call.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ def call(options = {}, flow_options = {}, **circuit_options)

# @private Please do not override this method as it might get removed.
def call_with_public_interface_from_call(options, flow_options, **circuit_options)
# extract valid circuit options (what is the definitive source for available circuit options?)
real_circuit_options, other_options = circuit_options.partition {|k,_v| reserved_circuit_option_names.include? k }.map(&:to_h)
# normalize options.
options = options
.merge(circuit_options) # when using Op.call(params:, ...), {circuit_options} will always be ctx variables.
.merge(other_options) # when using Op.call(params:, ...), {circuit_options} will always be ctx variables.

call_with_public_interface(options, flow_options)
call_with_public_interface(options, flow_options, real_circuit_options)
end

# Default {@activity} call interface which doesn't accept {circuit_options}
Expand Down Expand Up @@ -119,5 +121,9 @@ def self.call_task(wrap_ctx, original_args) # DISCUSS: copied from {TaskWrap.cal
def initial_wrap_static
INITIAL_WRAP_STATIC
end

def reserved_circuit_option_names
%i(wrap_runtime)
end
end
end
70 changes: 70 additions & 0 deletions test/call_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,74 @@ def self.add_1(wrap_ctx, original_args)

result.wtf?
end

it "invokes with the taskWrap defined at operation using the circuit interface" do
operation = Class.new(Trailblazer::Operation) do
include Trailblazer::Activity::Testing.def_steps(:a)

def self.add_1(wrap_ctx, original_args)
ctx, = original_args[0]
ctx[:seq] << 1
return wrap_ctx, original_args # yay to mutable state. not.
end

step :a
end

my_extension = Trailblazer::Activity::TaskWrap::Extension(
[operation.method(:add_1), id: "my.add_1", append: "task_wrap.call_task"]
)

# circuit interface invocation using invoke
ctx = { seq: [] }
signal, (ctx, _) = operation.invoke([ctx, {}], wrap_runtime: Hash.new(my_extension))
signal.to_h[:semantic].must_equal :success
ctx[:seq].must_equal [1, :a, 1, 1, 1]
end

it "calls with the taskWrap defined at operation using public interface" do
operation = Class.new(Trailblazer::Operation) do
include Trailblazer::Activity::Testing.def_steps(:a)

def self.add_1(wrap_ctx, original_args)
ctx, = original_args[0]
ctx[:seq] << 1
return wrap_ctx, original_args # yay to mutable state. not.
end

step :a
end

my_extension = Trailblazer::Activity::TaskWrap::Extension(
[operation.method(:add_1), id: "my.add_1", append: "task_wrap.call_task"]
)

# public interface invocation using call
result = operation.(seq: [], wrap_runtime: Hash.new(my_extension))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is - per design - not supposed to work as it's impossible for us to know which keyword argument is flow_options and what is circuit_options. It was a design mistake to try and make the public #call the swiss army knife of TRB...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should, but I'm afraid it doesn't. I tried to debug, where my wrap_runtime got lost. But got lost myself. Somehow it doesn't get called. Test is there to document this behaviour.

result.inspect(:seq).must_equal %{<Result:true [[1, :a, 1, 1, 1]] >}
end

it "calls with the taskWrap defined at operation using circuit interface" do
operation = Class.new(Trailblazer::Operation) do
include Trailblazer::Activity::Testing.def_steps(:a)

def self.add_1(wrap_ctx, original_args)
ctx, = original_args[0]
ctx[:seq] << 1
return wrap_ctx, original_args # yay to mutable state. not.
end

step :a
end

my_extension = Trailblazer::Activity::TaskWrap::Extension(
[operation.method(:add_1), id: "my.add_1", append: "task_wrap.call_task"]
)

# circuit interface invocation using call
ctx = { seq: [] }
signal, (ctx, _) = operation.call([ctx, {}], wrap_runtime: Hash.new(my_extension))
signal.to_h[:semantic].must_equal :success
ctx[:seq].must_equal [1, :a, 1, 1, 1]
end
end