-
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.
introduce
Advance
(finally! 😆) and extract start_task_position and
start_positions computation from an Iteration.
- Loading branch information
Showing
4 changed files
with
72 additions
and
6 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,35 @@ | ||
# Runtime | ||
module Trailblazer | ||
module Workflow | ||
module Advance | ||
module_function | ||
|
||
def call(schema, ctx, event_label:, iteration_set:, **) | ||
planned_iteration = iteration_set.to_a.find { |iteration| iteration.event_label == event_label } | ||
|
||
# TODO: run the state guard here. | ||
|
||
position_options = position_options_from_iteration(planned_iteration) # :start_task_position and :start_positions | ||
|
||
|
||
configuration, (ctx, flow) = Trailblazer::Workflow::Collaboration::Synchronous.advance( | ||
schema, | ||
[ctx, {throw: []}], | ||
{}, # circuit_options | ||
|
||
**position_options, | ||
message_flow: message_flow, | ||
) | ||
|
||
end | ||
|
||
# Computes {:start_task_position} and {:start_positions}. | ||
def position_options_from_iteration(iteration) | ||
{ | ||
start_task_position: iteration.start_task_position, # which event to trigger | ||
lane_positions: iteration.start_positions # current position/"state" | ||
} | ||
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
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,32 @@ | ||
require "test_helper" | ||
|
||
# high-level unit test that shows the user's interface. | ||
class AdvanceTest < Minitest::Spec | ||
include BuildSchema | ||
include DiscoveredStates | ||
|
||
it "what" do | ||
schema, lanes, message_flow, initial_lane_positions, lanes_cfg = build_schema() | ||
|
||
# TODO: this is something that shouldn't be done every time. | ||
states, lanes_sorted, lanes_cfg = states() | ||
|
||
iteration_set = Trailblazer::Workflow::Introspect::Iteration::Set.from_discovered_states(states, lanes_cfg: lanes_cfg) | ||
# "states" | ||
position_to_iterations_table = Trailblazer::Workflow::Introspect::StateTable.aggregate_by_state(iteration_set) | ||
|
||
ctx = {params: [], seq: []} | ||
|
||
# TODO: this should be suitable to be dropped into an endpoint. | ||
|
||
signal, (ctx, flow_options) = Trailblazer::Workflow::Advance.( | ||
schema, | ||
ctx, | ||
event_label: "☝ ⏵︎Update", | ||
lanes_cfg: lanes_cfg, # TODO: make this part of {schema}. | ||
|
||
iteration_set: iteration_set, # this is basically the "dictionary" for lookups of positions. | ||
state_guards: {} # TODO: design/implement this. | ||
) | ||
end | ||
end |