Class: Nexo::RunStore::ActiveRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/nexo/run_store.rb

Overview

ActiveRecord backend used by the Rails path. Delegates to the Nexo::WorkflowRun model, which carries the same run shape.

Instance Method Summary collapse

Instance Method Details

#claim_for_resume!(run) ⇒ Object

Atomically claims a "suspended" run for resume with a single conditional UPDATE, returning true only for the worker that won the row. This closes the cross-process double-resume race the plain +find+-then-check couldn't: a queued resume_later and a concurrent sync resume can't both re-enter.



155
156
157
158
159
# File 'lib/nexo/run_store.rb', line 155

def claim_for_resume!(run)
  Nexo::WorkflowRun
    .where(id: run.id, status: "suspended")
    .update_all(status: "running") == 1
end

#create(workflow_class:, payload:) ⇒ Object

Creates and persists a "pending" Nexo::WorkflowRun row, returning it.



144
145
146
# File 'lib/nexo/run_store.rb', line 144

def create(workflow_class:, payload:)
  Nexo::WorkflowRun.create!(workflow_class: workflow_class, payload: payload, status: "pending")
end

#find(id) ⇒ Object

Fetches a persisted run by id (raises ActiveRecord::RecordNotFound on a miss).



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

def find(id) = Nexo::WorkflowRun.find(id)