Class: SagaForge::Execution::Facade
- Inherits:
-
Object
- Object
- SagaForge::Execution::Facade
- Defined in:
- lib/saga_forge/execution/facade.rb
Overview
The saga object yielded to forward blocks (§A.1 verbs). Everything is
staged in memory; the Runner commits it.
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Verb semantics: last verb call wins — calling transition_to twice simply overwrites @outcome with whatever ran last, and the block keeps executing.
-
#correlation_id ⇒ Object
readonly
Verb semantics: last verb call wins — calling transition_to twice simply overwrites @outcome with whatever ran last, and the block keeps executing.
-
#current_state ⇒ Object
readonly
Verb semantics: last verb call wins — calling transition_to twice simply overwrites @outcome with whatever ran last, and the block keeps executing.
-
#outcome ⇒ Object
readonly
Verb semantics: last verb call wins — calling transition_to twice simply overwrites @outcome with whatever ran last, and the block keeps executing.
-
#staged_publishes ⇒ Object
readonly
Verb semantics: last verb call wins — calling transition_to twice simply overwrites @outcome with whatever ran last, and the block keeps executing.
Instance Method Summary collapse
- #fail!(reason: nil) ⇒ Object
-
#initialize(definition:, correlation_id:, current_state:, context:) ⇒ Facade
constructor
A new instance of Facade.
-
#publish(event_name, **payload) ⇒ Object
Staged publish (§A.2): resolve recipients NOW (call-site stack trace, MissingCorrelationError surfaces under the block's retry policy), hold fully-built rows; the Runner inserts them inside its commit.
- #transition_to(state) ⇒ Object
Constructor Details
#initialize(definition:, correlation_id:, current_state:, context:) ⇒ Facade
Returns a new instance of Facade.
14 15 16 17 18 19 20 21 |
# File 'lib/saga_forge/execution/facade.rb', line 14 def initialize(definition:, correlation_id:, current_state:, context:) @definition = definition @correlation_id = correlation_id @current_state = current_state @context = context @staged_publishes = [] @outcome = nil end |
Instance Attribute Details
#context ⇒ Object (readonly)
Verb semantics: last verb call wins — calling transition_to twice simply overwrites @outcome with whatever ran last, and the block keeps executing. fail! is the one exception: it both records its outcome AND throws :saga_forge_fail, short-circuiting the rest of the block immediately. Every other verb is just a plain method call with no control-flow effect.
12 13 14 |
# File 'lib/saga_forge/execution/facade.rb', line 12 def context @context end |
#correlation_id ⇒ Object (readonly)
Verb semantics: last verb call wins — calling transition_to twice simply overwrites @outcome with whatever ran last, and the block keeps executing. fail! is the one exception: it both records its outcome AND throws :saga_forge_fail, short-circuiting the rest of the block immediately. Every other verb is just a plain method call with no control-flow effect.
12 13 14 |
# File 'lib/saga_forge/execution/facade.rb', line 12 def correlation_id @correlation_id end |
#current_state ⇒ Object (readonly)
Verb semantics: last verb call wins — calling transition_to twice simply overwrites @outcome with whatever ran last, and the block keeps executing. fail! is the one exception: it both records its outcome AND throws :saga_forge_fail, short-circuiting the rest of the block immediately. Every other verb is just a plain method call with no control-flow effect.
12 13 14 |
# File 'lib/saga_forge/execution/facade.rb', line 12 def current_state @current_state end |
#outcome ⇒ Object (readonly)
Verb semantics: last verb call wins — calling transition_to twice simply overwrites @outcome with whatever ran last, and the block keeps executing. fail! is the one exception: it both records its outcome AND throws :saga_forge_fail, short-circuiting the rest of the block immediately. Every other verb is just a plain method call with no control-flow effect.
12 13 14 |
# File 'lib/saga_forge/execution/facade.rb', line 12 def outcome @outcome end |
#staged_publishes ⇒ Object (readonly)
Verb semantics: last verb call wins — calling transition_to twice simply overwrites @outcome with whatever ran last, and the block keeps executing. fail! is the one exception: it both records its outcome AND throws :saga_forge_fail, short-circuiting the rest of the block immediately. Every other verb is just a plain method call with no control-flow effect.
12 13 14 |
# File 'lib/saga_forge/execution/facade.rb', line 12 def staged_publishes @staged_publishes end |
Instance Method Details
#fail!(reason: nil) ⇒ Object
31 32 33 34 |
# File 'lib/saga_forge/execution/facade.rb', line 31 def fail!(reason: nil) @outcome = [:fail, reason] throw :saga_forge_fail end |
#publish(event_name, **payload) ⇒ Object
Staged publish (§A.2): resolve recipients NOW (call-site stack trace, MissingCorrelationError surfaces under the block's retry policy), hold fully-built rows; the Runner inserts them inside its commit.
39 40 41 42 |
# File 'lib/saga_forge/execution/facade.rb', line 39 def publish(event_name, **payload) @staged_publishes.concat(Router.resolve(event_name, payload)) nil end |
#transition_to(state) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/saga_forge/execution/facade.rb', line 23 def transition_to(state) unless @definition.declared?(state) raise UnknownStateError, "transition_to #{state.inspect} — undeclared state" end @outcome = [:transition_to, state.to_sym] nil end |