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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#artifactsObject

Returns the value of attribute artifacts

Returns:

  • (Object)

    the current value of artifacts



45
46
47
# File 'lib/nexo/run_store.rb', line 45

def artifacts
  @artifacts
end

#errorObject

Returns the value of attribute error

Returns:

  • (Object)

    the current value of error



45
46
47
# File 'lib/nexo/run_store.rb', line 45

def error
  @error
end

#eventsObject

Returns the value of attribute events

Returns:

  • (Object)

    the current value of events



45
46
47
# File 'lib/nexo/run_store.rb', line 45

def events
  @events
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



45
46
47
# File 'lib/nexo/run_store.rb', line 45

def id
  @id
end

#payloadObject

Returns the value of attribute payload

Returns:

  • (Object)

    the current value of payload



45
46
47
# File 'lib/nexo/run_store.rb', line 45

def payload
  @payload
end

#resultObject

Returns the value of attribute result

Returns:

  • (Object)

    the current value of result



45
46
47
# File 'lib/nexo/run_store.rb', line 45

def result
  @result
end

#stateObject

Returns the value of attribute state

Returns:

  • (Object)

    the current value of state



45
46
47
# File 'lib/nexo/run_store.rb', line 45

def state
  @state
end

#statusObject

Returns the value of attribute status

Returns:

  • (Object)

    the current value of status



45
46
47
# File 'lib/nexo/run_store.rb', line 45

def status
  @status
end

#workflow_classObject

Returns the value of attribute workflow_class

Returns:

  • (Object)

    the current value of 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).

Returns:

  • (Boolean)


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

def done? = status == "done"

#failed?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


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

def queued? = status == "queued"

#running?Boolean

Returns:

  • (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_reasonObject

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

Returns:

  • (Boolean)


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

def suspended? = status == "suspended"

#update!(attrs) ⇒ Object



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

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