Class: SagaForge::Base
- Inherits:
-
Object
- Object
- SagaForge::Base
- Defined in:
- lib/saga_forge/base.rb
Overview
The saga DSL. Macros only record; Definition.compile (lazy, memoized) builds and validates the machine. The file IS the state machine.
Class Attribute Summary collapse
-
.correlator ⇒ Object
readonly
Returns the value of attribute correlator.
-
.default_retry_policy ⇒ Object
readonly
Returns the value of attribute default_retry_policy.
Class Method Summary collapse
- .compensation(name, &block) ⇒ Object
- .correlate_by(key = nil, &block) ⇒ Object
- .declarations ⇒ Object
- .definition ⇒ Object
- .during(state, on:, compensate: nil, timeout: nil, on_timeout: nil, retry_policy: nil, &block) ⇒ Object
-
.find_by_correlation(correlation_id) ⇒ Object
Introspection & recovery (class-level; instance ops land in Task 11).
- .finish_with(state) ⇒ Object
- .in_state(state) ⇒ Object
- .inherited(subclass) ⇒ Object
- .retry_policy(*policies, **kwargs) ⇒ Object
- .stalled ⇒ Object
- .start_with(event, compensate: nil, timeout: nil, on_timeout: nil, retry_policy: nil, &block) ⇒ Object
- .suspended ⇒ Object
- .to_mermaid ⇒ Object
Class Attribute Details
.correlator ⇒ Object (readonly)
Returns the value of attribute correlator.
6 7 8 |
# File 'lib/saga_forge/base.rb', line 6 def correlator @correlator end |
.default_retry_policy ⇒ Object (readonly)
Returns the value of attribute default_retry_policy.
6 7 8 |
# File 'lib/saga_forge/base.rb', line 6 def default_retry_policy @default_retry_policy end |
Class Method Details
.compensation(name, &block) ⇒ Object
29 30 31 |
# File 'lib/saga_forge/base.rb', line 29 def compensation(name, &block) declarations << {kind: :compensation, name: name.to_sym, block:} end |
.correlate_by(key = nil, &block) ⇒ Object
13 14 15 |
# File 'lib/saga_forge/base.rb', line 13 def correlate_by(key = nil, &block) @correlator = block || ->(payload, _event = nil) { payload[key] } end |
.declarations ⇒ Object
45 |
# File 'lib/saga_forge/base.rb', line 45 def declarations = @declarations ||= [] |
.definition ⇒ Object
47 |
# File 'lib/saga_forge/base.rb', line 47 def definition = @definition ||= Definition.compile(self) |
.during(state, on:, compensate: nil, timeout: nil, on_timeout: nil, retry_policy: nil, &block) ⇒ Object
21 22 23 |
# File 'lib/saga_forge/base.rb', line 21 def during(state, on:, compensate: nil, timeout: nil, on_timeout: nil, retry_policy: nil, &block) declarations << {kind: :during, state: state.to_sym, event: on.to_sym, compensate:, timeout:, on_timeout:, retry_policy:, block:} end |
.find_by_correlation(correlation_id) ⇒ Object
Introspection & recovery (class-level; instance ops land in Task 11).
50 |
# File 'lib/saga_forge/base.rb', line 50 def find_by_correlation(correlation_id) = State.for_saga(self).find_by(correlation_id: correlation_id.to_s) |
.finish_with(state) ⇒ Object
25 26 27 |
# File 'lib/saga_forge/base.rb', line 25 def finish_with(state) declarations << {kind: :finish, state: state.to_sym} end |
.in_state(state) ⇒ Object
52 |
# File 'lib/saga_forge/base.rb', line 52 def in_state(state) = State.for_saga(self).in_state(state) |
.inherited(subclass) ⇒ Object
8 9 10 11 |
# File 'lib/saga_forge/base.rb', line 8 def inherited(subclass) super Router.register(subclass) end |
.retry_policy(*policies, **kwargs) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/saga_forge/base.rb', line 33 def retry_policy(*policies, **kwargs) if policies.any? && kwargs.any? raise ArgumentError, "pass either policy objects or kwargs, not both" end @default_retry_policy = if policies.any? (policies.size == 1 && kwargs.empty?) ? policies.first : CompositeRetryPolicy.new(policies) else RetryPolicy.new(**kwargs) end end |
.stalled ⇒ Object
54 |
# File 'lib/saga_forge/base.rb', line 54 def stalled = State.for_saga(self).stalled |
.start_with(event, compensate: nil, timeout: nil, on_timeout: nil, retry_policy: nil, &block) ⇒ Object
17 18 19 |
# File 'lib/saga_forge/base.rb', line 17 def start_with(event, compensate: nil, timeout: nil, on_timeout: nil, retry_policy: nil, &block) declarations << {kind: :start, event: event.to_sym, compensate:, timeout:, on_timeout:, retry_policy:, block:} end |
.suspended ⇒ Object
56 |
# File 'lib/saga_forge/base.rb', line 56 def suspended = State.for_saga(self).suspended |
.to_mermaid ⇒ Object
58 |
# File 'lib/saga_forge/base.rb', line 58 def to_mermaid = definition.to_mermaid |