Skip to content

Commit

Permalink
add :semantic to our initial "suspend".
Browse files Browse the repository at this point in the history
implement printing a state table that shows all states we reached
with the state discovery.
  • Loading branch information
apotonick committed Dec 14, 2023
1 parent 4e1a85b commit 751c7ea
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/trailblazer/workflow/collaboration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def initial_lane_positions(lanes)

[
activity,
{"resumes" => [catch_id]} # We deliberately have *one* position per lane, we're Synchronous.
{"resumes" => [catch_id], semantic: [:suspend, "from initial_lane_positions"]} # We deliberately have *one* position per lane, we're Synchronous. # TODO: use a real {Event::Suspend} here.
]
end
.to_h
Expand Down
43 changes: 40 additions & 3 deletions test/collaboration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ def decider(ctx, decision: true, **)
already_visited_catch_events_again[start_task] = true
end

# register new state.
states << [lane_positions, start_position]

configuration, (ctx, flow) = Trailblazer::Workflow::Collaboration::Synchronous.advance(
schema,
[ctx, {throw: []}],
Expand All @@ -202,8 +205,6 @@ def decider(ctx, decision: true, **)
message_flow: extended_message_flow,
)

# register new state.
states << configuration

# figure out possible next resumes/catchs:
last_lane = configuration.last_lane
Expand All @@ -230,6 +231,42 @@ def decider(ctx, decision: true, **)
end
end

# here, we only have the resume/catch events.
# pp states

def render_states(states, lanes:)
rows = states.collect do |lane_positions, triggered_resume_event|

# Go through each lane.
row = lane_positions.flat_map do |activity, suspend|
next if suspend.to_h["resumes"].nil?

resumes = suspend.to_h["resumes"].collect do |catch_event_id|
catch_event = Trailblazer::Activity::Introspect.Nodes(activity, id: catch_event_id).task
task_after_catch = activity.to_h[:circuit].to_h[:map][catch_event][Trailblazer::Activity::Right]
# raise task_after_catch.inspect

Trailblazer::Activity::Introspect.Nodes(activity, task: task_after_catch).data[:label] || task_after_catch
end

[
lanes[activity],
resumes.inspect,

"#{lanes[activity]} suspend",
suspend.to_h[:semantic][1]
]
end

row = Hash[*row.compact]
end
.uniq # remove me if you want to see all reached configurations


puts Hirb::Helpers::Table.render(rows, fields: ["UI", "UI suspend", "lifecycle", "lifecycle suspend"], max_width: 999)
end

render_states(states, lanes: {lane_activity => "lifecycle", lane_activity_ui => "UI", approver_activity => "approver"})



Expand All @@ -253,7 +290,7 @@ def decider(ctx, decision: true, **)

# TODO: test {:last_lane}.
assert_equal configuration.lane_positions.keys, [lane_activity, lane_activity_ui]
assert_equal configuration.lane_positions.values.inspect, %([{"resumes"=>["catch-before-#{create_id}"]}, \
assert_equal configuration.lane_positions.values.inspect, %([{"resumes"=>["catch-before-#{create_id}"], :semantic=>[:suspend, "from initial_lane_positions"]}, \
#<Trailblazer::Workflow::Event::Suspend resumes=["catch-before-#{ui_create}"] type=:suspend semantic=[:suspend, "suspend-Gateway_14h0q7a"]>])
assert_equal ctx.inspect, %({:seq=>[:create_form]})

Expand Down

0 comments on commit 751c7ea

Please sign in to comment.