Skip to content

Commit

Permalink
handle advance error further up.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Apr 4, 2024
1 parent 61017ae commit 9a44ed8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
13 changes: 9 additions & 4 deletions lib/trailblazer/workflow/advance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ class Advance < Trailblazer::Activity::Railway
terminus :invalid_event

step task: :compute_catch_event_tuple, Output(:failure) => Track(:invalid_event)
step task: :find_position_options
step task: :find_position_options, Output(:failure) => Track(:invalid_event)
step task: :advance

# DISCUSS: what we actually want here is a "catch_event tuple", the event we want to trigger.
# currently, we receive an {event_label}, find that in the iteration_set and thus
# get the catch event.
def compute_catch_event_tuple((ctx, flow_options), **)
iteration_set, event_label = flow_options[:iteration_set], flow_options[:event_label]

Expand Down Expand Up @@ -46,9 +49,11 @@ def position_options_from_iteration(iteration)
def find_position_options((ctx, flow_options), **)
state_resolver = flow_options[:state_guards]

_, state_options = state_resolver.(*flow_options[:catch_event_tuple], [ctx], **ctx.to_hash)

# raise unless state_options # FIXME.
(_, state_options), possible_states = state_resolver.(*flow_options[:catch_event_tuple], [ctx], **ctx.to_hash)
unless state_options
flow_options[:errors] = "No state configuration found for #{possible_states.inspect}"
return Activity::Left, [ctx, flow_options] # FIXME: make this nicer.
end

lanes_cfg = flow_options[:lanes]
fixme_tuples = state_options[:suspend_tuples].collect { |tuple| {"tuple" => tuple} }
Expand Down
5 changes: 1 addition & 4 deletions lib/trailblazer/workflow/collaboration/state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ def call(lane_label, catch_id, args, **kws)
# First, find all state guards that "point to" this catch event.
possible_states = @table.find_all { |state_name, cfg| cfg[:catch_tuples].include?([lane_label, catch_id]) }


# Execute those, the first returning true indicates the configuration.
target_state = possible_states.find { |state_name, cfg| @guards.(state_name, args, **kws) }

raise "No state configuration found for #{possible_states.inspect}" if target_state.nil?

target_state
return target_state, possible_states
end
end
end
Expand Down
12 changes: 11 additions & 1 deletion test/advance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,22 @@ class AdvanceTest < Minitest::Spec
assert_equal signal.inspect, %(#<Trailblazer::Activity::End semantic=:success>)


#@ unknown event label
#@ unknown event label
flow_options = flow_options.merge!(event_label: "XXX unknown ~~~")

signal, (ctx, flow_options) = Trailblazer::Workflow::Advance.([ctx_for_advance, flow_options])

assert_equal signal.inspect, %(#<Trailblazer::Activity::End semantic=:invalid_event>)

#@ no state guard matches
# DISCUSS: should we stop on a different terminus here to indicate that we found matching guards, but they were all unmet?
flow_options = flow_options.merge!(event_label: "☝ ⏵︎Update")
ctx_for_advance = {model: Posting.new(state: "~~~undefined~~~")}

signal, (ctx, flow_options) = Trailblazer::Workflow::Advance.([ctx_for_advance, flow_options])

assert_equal signal.inspect, %(#<Trailblazer::Activity::End semantic=:invalid_event>)
assert_equal flow_options[:errors], %(No state configuration found for [[\"⏸︎ Update [00u]\", {:suspend_tuples=>[[\"lifecycle\", \"suspend-Gateway_0fnbg3r\"], [\"UI\", \"suspend-Gateway_0nxerxv\"], [\"approver\", \"~suspend~\"]], :catch_tuples=>[[\"UI\", \"catch-before-Activity_0j78uzd\"]]}]])
end
end

Expand Down

0 comments on commit 9a44ed8

Please sign in to comment.