Module: Igniter::Extensions::Contracts::ReactivePack
- Defined in:
- lib/igniter/extensions/contracts/reactive_pack.rb
Class Method Summary collapse
- .build(&block) ⇒ Object
- .build_events(target, execution_result:) ⇒ Object
- .dispatch(target, reactions:) ⇒ Object
- .dispatch_failure(error, reactions:) ⇒ Object
- .install_into(kernel) ⇒ Object
- .manifest ⇒ Object
- .run(environment, inputs:, reactions:, compiled_graph: nil, &block) ⇒ Object
- .run_incremental(session, inputs:, reactions:) ⇒ Object
- .unwrap_execution_result(target) ⇒ Object
Class Method Details
.build(&block) ⇒ Object
28 29 30 |
# File 'lib/igniter/extensions/contracts/reactive_pack.rb', line 28 def build(&block) Reactive::Builder.build(&block) end |
.build_events(target, execution_result:) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/igniter/extensions/contracts/reactive_pack.rb', line 113 def build_events(target, execution_result:) events = [] events << Reactive::Event.new( event_id: "execution_succeeded", type: :execution_succeeded, path: :execution, status: :succeeded, payload: { output_names: execution_result.outputs.keys } ) execution_result.outputs.to_h.each do |name, value| events << Reactive::Event.new( event_id: "output_produced:#{name}", type: :output_produced, path: name, status: :succeeded, payload: { value: value } ) end if target.respond_to?(:changed_outputs) target.changed_outputs.each do |name, change| events << Reactive::Event.new( event_id: "output_changed:#{name}", type: :output_changed, path: name, status: :succeeded, payload: { value: execution_result.output(name), previous_value: change[:from], current_value: change[:to] } ) end end events << Reactive::Event.new( event_id: "execution_exited", type: :execution_exited, path: :execution, status: :succeeded, payload: { output_names: execution_result.outputs.keys } ) events.freeze end |
.dispatch(target, reactions:) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/igniter/extensions/contracts/reactive_pack.rb', line 32 def dispatch(target, reactions:) result = target execution_result = unwrap_execution_result(target) events = build_events(target, execution_result: execution_result) engine = Reactive::Engine.new(plan: reactions) engine.call(events: events, result: result, execution_result: execution_result) Reactive::DispatchResult.new( status: :succeeded, events: events, errors: engine.errors, result: result, execution_result: execution_result ) end |
.dispatch_failure(error, reactions:) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/igniter/extensions/contracts/reactive_pack.rb', line 70 def dispatch_failure(error, reactions:) events = [ Reactive::Event.new( event_id: "execution_failed", type: :execution_failed, path: :execution, status: :failed, payload: { error_type: error.class.name, error_message: error. } ), Reactive::Event.new( event_id: "execution_exited", type: :execution_exited, path: :execution, status: :failed, payload: { error_type: error.class.name, error_message: error. } ) ] engine = Reactive::Engine.new(plan: reactions) engine.call(events: events, result: nil, execution_result: nil, execution_error: error) Reactive::DispatchResult.new( status: :failed, events: events, errors: engine.errors, result: nil, execution_result: nil, execution_error: error ) end |
.install_into(kernel) ⇒ Object
24 25 26 |
# File 'lib/igniter/extensions/contracts/reactive_pack.rb', line 24 def install_into(kernel) kernel end |
.manifest ⇒ Object
17 18 19 20 21 22 |
# File 'lib/igniter/extensions/contracts/reactive_pack.rb', line 17 def manifest Igniter::Contracts::PackManifest.new( name: :extensions_reactive, metadata: { category: :orchestration } ) end |
.run(environment, inputs:, reactions:, compiled_graph: nil, &block) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/igniter/extensions/contracts/reactive_pack.rb', line 49 def run(environment, inputs:, reactions:, compiled_graph: nil, &block) graph = if block environment.compile(&block) else compiled_graph || raise(ArgumentError, "reactive run requires a block or compiled_graph") end begin result = environment.execute(graph, inputs: inputs) dispatch(result, reactions: reactions) rescue StandardError => e dispatch_failure(e, reactions: reactions) end end |
.run_incremental(session, inputs:, reactions:) ⇒ Object
65 66 67 68 |
# File 'lib/igniter/extensions/contracts/reactive_pack.rb', line 65 def run_incremental(session, inputs:, reactions:) result = session.run(inputs: inputs) dispatch(result, reactions: reactions) end |
.unwrap_execution_result(target) ⇒ Object
107 108 109 110 111 |
# File 'lib/igniter/extensions/contracts/reactive_pack.rb', line 107 def unwrap_execution_result(target) return target.execution_result if target.respond_to?(:execution_result) target end |