Class: Nexo::RunStore::Memory::Run

Inherits:
Struct
  • Object
show all
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.

Direct Known Subclasses

Disk::Run

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#artifacts ⇒ Object

Returns the value of attribute artifacts

Returns:

  • (Object) —

    the current value of artifacts



56
57
58
# File 'lib/nexo/run_store.rb', line 56

def artifacts
  @artifacts
end

#error ⇒ Object

Returns the value of attribute error

Returns:

  • (Object) —

    the current value of error



56
57
58
# File 'lib/nexo/run_store.rb', line 56

def error
  @error
end

#events ⇒ Object

Returns the value of attribute events

Returns:

  • (Object) —

    the current value of events



56
57
58
# File 'lib/nexo/run_store.rb', line 56

def events
  @events
end

#id ⇒ Object

Returns the value of attribute id

Returns:

  • (Object) —

    the current value of id



56
57
58
# File 'lib/nexo/run_store.rb', line 56

def id
  @id
end

#payload ⇒ Object

Returns the value of attribute payload

Returns:

  • (Object) —

    the current value of payload



56
57
58
# File 'lib/nexo/run_store.rb', line 56

def payload
  @payload
end

#result ⇒ Object

Returns the value of attribute result

Returns:

  • (Object) —

    the current value of result



56
57
58
# File 'lib/nexo/run_store.rb', line 56

def result
  @result
end

#state ⇒ Object

Returns the value of attribute state

Returns:

  • (Object) —

    the current value of state



56
57
58
# File 'lib/nexo/run_store.rb', line 56

def state
  @state
end

#status ⇒ Object

Returns the value of attribute status

Returns:

  • (Object) —

    the current value of status



56
57
58
# File 'lib/nexo/run_store.rb', line 56

def status
  @status
end

#workflow_class ⇒ Object

Returns the value of attribute workflow_class

Returns:

  • (Object) —

    the current value of workflow_class



56
57
58
# File 'lib/nexo/run_store.rb', line 56

def workflow_class
  @workflow_class
end

Instance Method Details

#artifact(name) ⇒ Object

A recorded artifact by name (string/symbol tolerant), or nil.



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

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.



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

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.



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

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).

Returns:

  • (Boolean)


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

def done? = status == "done"

#failed? ⇒ Boolean

Returns:

  • (Boolean)


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

def failed? = status == "failed"

#push_artifact(a) ⇒ Object



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

def push_artifact(a) = Memory.mutex.synchronize { artifacts << a }

#push_event(ev) ⇒ Object



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

def push_event(ev) = Memory.mutex.synchronize { events << ev }

#queued? ⇒ Boolean

Returns:

  • (Boolean)


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

def queued? = status == "queued"

#running? ⇒ Boolean

Returns:

  • (Boolean)


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

def running? = status == "running"

#save_artifacts! ⇒ Object



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

def save_artifacts! = nil

#save_events! ⇒ Object



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

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).



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

def save_state! = nil

#suspend_reason ⇒ Object

The reason recorded when the run was suspended, or nil if it never was.



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

def suspend_reason = state&.dig("__suspend__", "reason")

#suspended? ⇒ Boolean

Returns:

  • (Boolean)


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

def suspended? = status == "suspended"

#update!(attrs) ⇒ Object



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

def update!(attrs) = Memory.mutex.synchronize { attrs.each { |k, v| self[k] = v } }