Class: RubyReactor::Reactor
- Inherits:
-
Object
- Object
- RubyReactor::Reactor
- Includes:
- Dsl::Reactor
- Defined in:
- lib/ruby_reactor/reactor.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#execution_trace ⇒ Object
readonly
Returns the value of attribute execution_trace.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#undo_trace ⇒ Object
readonly
Returns the value of attribute undo_trace.
Instance Method Summary collapse
-
#initialize(context = {}) ⇒ Reactor
constructor
A new instance of Reactor.
- #run(inputs = {}) ⇒ Object
- #validate! ⇒ Object
Methods included from Dsl::Reactor
Constructor Details
#initialize(context = {}) ⇒ Reactor
Returns a new instance of Reactor.
9 10 11 12 13 14 |
# File 'lib/ruby_reactor/reactor.rb', line 9 def initialize(context = {}) @context = context @result = :unexecuted @undo_trace = [] @execution_trace = [] end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
7 8 9 |
# File 'lib/ruby_reactor/reactor.rb', line 7 def context @context end |
#execution_trace ⇒ Object (readonly)
Returns the value of attribute execution_trace.
7 8 9 |
# File 'lib/ruby_reactor/reactor.rb', line 7 def execution_trace @execution_trace end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
7 8 9 |
# File 'lib/ruby_reactor/reactor.rb', line 7 def result @result end |
#undo_trace ⇒ Object (readonly)
Returns the value of attribute undo_trace.
7 8 9 |
# File 'lib/ruby_reactor/reactor.rb', line 7 def undo_trace @undo_trace end |
Instance Method Details
#run(inputs = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ruby_reactor/reactor.rb', line 16 def run(inputs = {}) if self.class.async? # For async reactors, enqueue the job and return immediately context = Context.new(inputs, self.class) serialized_context = ContextSerializer.serialize(context) configuration.async_router.perform_async(serialized_context) else # For sync reactors (potentially with async steps), execute normally executor = Executor.new(self.class, inputs) @result = executor.execute @context = executor.context @undo_trace = executor.undo_trace @execution_trace = executor.execution_trace # If execution returned an AsyncResult (from step-level async), return it return @result if @result.is_a?(RubyReactor::AsyncResult) @result end end |
#validate! ⇒ Object
39 40 41 42 43 44 |
# File 'lib/ruby_reactor/reactor.rb', line 39 def validate! # Validate reactor configuration validate_steps! validate_return_step! validate_dependencies! end |