Class: RcrewAI::Rails::FlowRun
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- RcrewAI::Rails::FlowRun
- Defined in:
- app/models/rcrewai/rails/flow_run.rb
Class Method Summary collapse
-
.execute(flow_class, inputs: {}) ⇒ Object
Runs a Flow subclass (a Class or its String name) with an AR-backed state store, wrapped in a run record.
Instance Method Summary collapse
Class Method Details
.execute(flow_class, inputs: {}) ⇒ Object
Runs a Flow subclass (a Class or its String name) with an AR-backed state store, wrapped in a run record. Returns the run. Re-raises on failure after recording it.
18 19 20 21 22 23 |
# File 'app/models/rcrewai/rails/flow_run.rb', line 18 def self.execute(flow_class, inputs: {}) klass = flow_class.is_a?(String) ? flow_class.constantize : flow_class run = create!(flow_class: klass.name, status: "pending", inputs: inputs) run.run!(klass, inputs) run end |
Instance Method Details
#run!(klass, inputs) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/models/rcrewai/rails/flow_run.rb', line 25 def run!(klass, inputs) update!(status: "running", started_at: Time.current) flow = klass.new(state_store: ActiveRecordStateStore.new) state = flow.kickoff(inputs: inputs) update!( status: "completed", state_id: state.id, result: state.to_h, completed_at: Time.current ) rescue => e update!(status: "failed", error_message: e., completed_at: Time.current) raise end |