Class: Nexo::RunStore::Memory::Run
- Inherits:
-
Struct
- Object
- Struct
- Nexo::RunStore::Memory::Run
- Defined in:
- lib/nexo/run_store.rb
Overview
A run record with the shared store shape. update! assigns attributes,
push_event appends to the event log, and save_events! is a no-op
(the AR backend persists; Memory keeps everything in the Struct).
Built with keyword arguments; a Struct defined without keyword_init:
accepts them on Ruby 3.2+, so (well within the 3.3 floor) +keyword_init:
true+ is unnecessary.
Mutations serialize on the store-wide mutex (see Memory.mutex): the
process-wide store can be driven from multiple threads (Local#offload
workers, run_later under a threaded adapter, a multithreaded Puma host
without ActiveRecord), and on Rubies without a GVL a bare +<<+/+[]=+ can
lose events or corrupt the table.
Instance Attribute Summary collapse
-
#artifacts ⇒ Object
Returns the value of attribute artifacts.
-
#error ⇒ Object
Returns the value of attribute error.
-
#events ⇒ Object
Returns the value of attribute events.
-
#id ⇒ Object
Returns the value of attribute id.
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#result ⇒ Object
Returns the value of attribute result.
-
#state ⇒ Object
Returns the value of attribute state.
-
#status ⇒ Object
Returns the value of attribute status.
-
#workflow_class ⇒ Object
Returns the value of attribute workflow_class.
Instance Method Summary collapse
-
#artifact(name) ⇒ Object
A recorded artifact by name (string/symbol tolerant), or nil.
-
#artifact_content(name) ⇒ Object
Just the stored body of a named artifact, or nil.
-
#checkpoint_result(name) ⇒ Object
The stored result of a completed checkpoint(name), or nil.
-
#done? ⇒ Boolean
Read helpers mirroring Nexo::WorkflowRun so host code written against a finished run behaves identically in plain Ruby and under Rails (the "same run shape" contract covered only the write side before).
- #failed? ⇒ Boolean
- #push_artifact(a) ⇒ Object
- #push_event(ev) ⇒ Object
- #queued? ⇒ Boolean
- #running? ⇒ Boolean
- #save_artifacts! ⇒ Object
- #save_events! ⇒ Object
-
#save_state! ⇒ Object
No-op counterpart to the AR model's save_state! — the Struct member already holds the checkpoint/suspend state in memory (Spec 13).
-
#suspend_reason ⇒ Object
The reason recorded when the run was suspended, or nil if it never was.
- #suspended? ⇒ Boolean
- #update!(attrs) ⇒ Object
Instance Attribute Details
#artifacts ⇒ Object
Returns the value of attribute artifacts
45 46 47 |
# File 'lib/nexo/run_store.rb', line 45 def artifacts @artifacts end |
#error ⇒ Object
Returns the value of attribute error
45 46 47 |
# File 'lib/nexo/run_store.rb', line 45 def error @error end |
#events ⇒ Object
Returns the value of attribute events
45 46 47 |
# File 'lib/nexo/run_store.rb', line 45 def events @events end |
#id ⇒ Object
Returns the value of attribute id
45 46 47 |
# File 'lib/nexo/run_store.rb', line 45 def id @id end |
#payload ⇒ Object
Returns the value of attribute payload
45 46 47 |
# File 'lib/nexo/run_store.rb', line 45 def payload @payload end |
#result ⇒ Object
Returns the value of attribute result
45 46 47 |
# File 'lib/nexo/run_store.rb', line 45 def result @result end |
#state ⇒ Object
Returns the value of attribute state
45 46 47 |
# File 'lib/nexo/run_store.rb', line 45 def state @state end |
#status ⇒ Object
Returns the value of attribute status
45 46 47 |
# File 'lib/nexo/run_store.rb', line 45 def status @status end |
#workflow_class ⇒ Object
Returns the value of attribute workflow_class
45 46 47 |
# File 'lib/nexo/run_store.rb', line 45 def workflow_class @workflow_class end |
Instance Method Details
#artifact(name) ⇒ Object
A recorded artifact by name (string/symbol tolerant), or nil.
80 |
# File 'lib/nexo/run_store.rb', line 80 def artifact(name) = (artifacts || []).find { |a| (a["name"] || a[:name]) == name.to_s } |
#artifact_content(name) ⇒ Object
Just the stored body of a named artifact, or nil.
83 |
# File 'lib/nexo/run_store.rb', line 83 def artifact_content(name) = artifact(name)&.then { |a| a["content"] || a[:content] } |
#checkpoint_result(name) ⇒ Object
The stored result of a completed checkpoint(name), or nil.
77 |
# File 'lib/nexo/run_store.rb', line 77 def checkpoint_result(name) = state&.[](name.to_s) |
#done? ⇒ Boolean
Read helpers mirroring Nexo::WorkflowRun so host code written against a finished run behaves identically in plain Ruby and under Rails (the "same run shape" contract covered only the write side before).
63 |
# File 'lib/nexo/run_store.rb', line 63 def done? = status == "done" |
#failed? ⇒ Boolean
65 |
# File 'lib/nexo/run_store.rb', line 65 def failed? = status == "failed" |
#push_artifact(a) ⇒ Object
52 |
# File 'lib/nexo/run_store.rb', line 52 def push_artifact(a) = Memory.mutex.synchronize { artifacts << a } |
#push_event(ev) ⇒ Object
48 |
# File 'lib/nexo/run_store.rb', line 48 def push_event(ev) = Memory.mutex.synchronize { events << ev } |
#queued? ⇒ Boolean
69 |
# File 'lib/nexo/run_store.rb', line 69 def queued? = status == "queued" |
#running? ⇒ Boolean
67 |
# File 'lib/nexo/run_store.rb', line 67 def running? = status == "running" |
#save_artifacts! ⇒ Object
54 |
# File 'lib/nexo/run_store.rb', line 54 def save_artifacts! = nil |
#save_events! ⇒ Object
50 |
# File 'lib/nexo/run_store.rb', line 50 def save_events! = nil |
#save_state! ⇒ Object
No-op counterpart to the AR model's save_state! — the Struct member already holds the checkpoint/suspend state in memory (Spec 13).
58 |
# File 'lib/nexo/run_store.rb', line 58 def save_state! = nil |
#suspend_reason ⇒ Object
The reason recorded when the run was suspended, or nil if it never was.
74 |
# File 'lib/nexo/run_store.rb', line 74 def suspend_reason = state&.dig("__suspend__", "reason") |
#suspended? ⇒ Boolean
71 |
# File 'lib/nexo/run_store.rb', line 71 def suspended? = status == "suspended" |