Class: Phronomy::StateStore::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/phronomy/state_store/base.rb

Overview

Abstract base class for workflow state persistence backends.

Subclasses must implement #load, #save, and #delete. A snapshot is a plain +Hash+ with two keys: +:fields+ — output of +context.to_h+ +:phase+ — +context.phase.to_s+

Examples:

Implementing a custom backend

class MyStore < Phronomy::StateStore::Base
  def load(thread_id) = MyRecord.find_by(thread_id:)&.to_h
  def save(thread_id, snapshot) = MyRecord.upsert(thread_id:, data: snapshot)
  def delete(thread_id) = MyRecord.where(thread_id:).delete_all
end

Direct Known Subclasses

InMemory

Instance Method Summary collapse

Instance Method Details

#delete(thread_id) ⇒ void

This method returns an undefined value.

Delete the stored snapshot for +thread_id+. No-op if absent.

Parameters:

  • thread_id (String)

Raises:

  • (NotImplementedError)


43
44
45
# File 'lib/phronomy/state_store/base.rb', line 43

def delete(thread_id)
  raise NotImplementedError, "#{self.class}#delete is not implemented"
end

#load(thread_id) ⇒ Hash?

Load the stored snapshot for +thread_id+.

Parameters:

  • thread_id (String)

Returns:

  • (Hash, nil)

    stored snapshot hash, or +nil+ if absent

Raises:

  • (NotImplementedError)


24
25
26
# File 'lib/phronomy/state_store/base.rb', line 24

def load(thread_id)
  raise NotImplementedError, "#{self.class}#load is not implemented"
end

#save(thread_id, snapshot) ⇒ void

This method returns an undefined value.

Persist +snapshot+ for +thread_id+. Overwrites any existing snapshot.

Parameters:

  • thread_id (String)
  • snapshot (Hash)

    serialisable hash of workflow state

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/phronomy/state_store/base.rb', line 34

def save(thread_id, snapshot)
  raise NotImplementedError, "#{self.class}#save is not implemented"
end