Skip to content

Commit

Permalink
advance now plays with endpoints.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Mar 18, 2024
1 parent ec540ad commit 431be14
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions lib/trailblazer/workflow/advance.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,51 @@
# Runtime
module Trailblazer
module Workflow
module Advance
module_function
class Advance < Trailblazer::Activity::Railway
# UNAUTHORIZED_SIGNAL = "unauthorized"
step task: :find_position_options
step task: :event_valid?, Output(:failure) => End(:not_authorized)
step task: :advance

UNAUTHORIZED_SIGNAL = "unauthorized"
def find_position_options((ctx, flow_options), **)
iteration_set, event_label = flow_options[:iteration_set], flow_options[:event_label]

# Needs Iteration::Set and an {event_label}.
def call(ctx, event_label:, iteration_set:, message_flow:, state_guards:, **)
planned_iteration = iteration_set.to_a.find { |iteration| iteration.event_label == event_label }

# TODO: those positions could also be passed in manually, without using an Iteration::Set.
position_options = position_options_from_iteration(planned_iteration) # :start_task_position and :start_positions
flow_options[:position_options] = position_options_from_iteration(planned_iteration) # :start_task_position and :start_positions

return Activity::Right, [ctx, flow_options]
end

def event_valid?((ctx, flow_options), **)
position_options = flow_options[:position_options]
state_guards = flow_options[:state_guards]

result = state_guards.(ctx, start_task_position: position_options[:start_task_position])

return result ? Activity::Right : Activity::Left, [ctx, flow_options]
end

# Needs Iteration::Set and an {event_label}.
def advance((ctx, flow_options), **circuit_options)
message_flow, position_options, iteration_set = flow_options[:message_flow], flow_options[:position_options], flow_options[:iteration_set]

# TODO: run the state guard here.
# FIXME: fix flow_options!
return UNAUTHORIZED_SIGNAL, [ctx, {}] unless state_guards.(ctx, start_task_position: position_options[:start_task_position])

configuration, (ctx, flow_options) = Trailblazer::Workflow::Collaboration::Synchronous.advance(
[ctx, {throw: []}], # FIXME: allow flow_options and circuit_options!!!!!!!!!!!!!!!!!!!!!!!!!!
{}, # circuit_options
[ctx, {throw: []}.merge(flow_options)], # FIXME: allow flow_options, AND TEST IT PROPERLY and circuit_options!!!!!!!!!!!!!!!!!!!!!!!!!!
circuit_options, # circuit_options

**position_options,
message_flow: message_flow,
)

signal = return_signal_for(configuration, iteration_set, **position_options,)

return signal, [ctx, flow_options], configuration
flow_options[:configuration] = configuration

return signal, [ctx, flow_options]#, configuration
end

# Computes {:start_task_position} and {:start_positions}.
Expand Down

0 comments on commit 431be14

Please sign in to comment.