Class: RcrewAI::Rails::ActiveRecordStateStore
- Inherits:
-
Object
- Object
- RcrewAI::Rails::ActiveRecordStateStore
- Defined in:
- app/models/rcrewai/rails/active_record_state_store.rb
Overview
Persists rcrewai Flow state to the DB. Implements the core state-store
contract: save(id, hash) / load(id) => hash or nil. Pass an instance as
state_store: when constructing a Flow.
State is stored as JSON (see FlowState), so values must be JSON-native — the same constraint as the core FileStateStore. A single flow run persists from one process, so saves are effectively serial; a genuinely concurrent first-write for the same state_id would hit the unique index and raise ActiveRecord::RecordNotUnique (fail-loud, by design).
Instance Method Summary collapse
Instance Method Details
#load(id) ⇒ Object
19 20 21 |
# File 'app/models/rcrewai/rails/active_record_state_store.rb', line 19 def load(id) FlowState.find_by(state_id: id)&.data end |
#save(id, hash) ⇒ Object
13 14 15 16 17 |
# File 'app/models/rcrewai/rails/active_record_state_store.rb', line 13 def save(id, hash) record = FlowState.find_or_initialize_by(state_id: id) record.data = hash record.save! end |