Class: Nexo::RunStore::Disk::Run

Inherits:
Memory::Run show all
Defined in:
lib/nexo/run_store.rb

Overview

A Memory::Run that writes itself to path whenever Workflow saves it.

Instance Attribute Summary collapse

Attributes inherited from Memory::Run

#artifacts, #error, #events, #id, #payload, #result, #state, #status, #workflow_class

Instance Method Summary collapse

Methods inherited from Memory::Run

#artifact, #artifact_content, #checkpoint_result, #done?, #failed?, #push_artifact, #push_event, #queued?, #running?, #suspend_reason, #suspended?

Instance Attribute Details

#path ⇒ Object

Absolute path of this run's JSON document. Assigned by the store.



198
199
200
# File 'lib/nexo/run_store.rb', line 198

def path
  @path
end

Instance Method Details

#persist! ⇒ Object

Writes the document atomically — a temp file in the same directory, then a rename — so a crash mid-write cannot leave a truncated run behind.



219
220
221
222
223
224
225
# File 'lib/nexo/run_store.rb', line 219

def persist!
  return if path.nil?

  tmp = "#{path}.#{Process.pid}.tmp"
  ::File.write(tmp, JSON.generate(to_h.except(:path)))
  ::File.rename(tmp, path)
end

#save_artifacts! ⇒ Object

Writes the run after Workflow appended an artifact.



206
# File 'lib/nexo/run_store.rb', line 206

def save_artifacts! = persist!

#save_events! ⇒ Object

The three save hooks Workflow calls after mutating a run. Memory's are no-ops because the Struct already holds everything; here they are the whole point.



203
# File 'lib/nexo/run_store.rb', line 203

def save_events! = persist!

#save_state! ⇒ Object

Writes the run after Workflow stored checkpoint/suspend state.



209
# File 'lib/nexo/run_store.rb', line 209

def save_state! = persist!

#update!(attrs) ⇒ Object

Assigns attributes (Memory's behaviour) and writes the run.



212
213
214
215
# File 'lib/nexo/run_store.rb', line 212

def update!(attrs)
  super
  persist!
end