Module: Phronomy::Graph

Defined in:
lib/phronomy.rb,
lib/phronomy/graph.rb,
lib/phronomy/graph/state.rb,
lib/phronomy/graph/state_graph.rb,
lib/phronomy/graph/parallel_node.rb,
lib/phronomy/graph/compiled_graph.rb

Overview

Namespace for graph-related classes (StateGraph, State, ParallelNode, …). Also serves as the registry for State classes that may be serialized to external stores (Redis, DB). Call +register_state_class+ at application startup so that only known classes can be deserialized.

Defined Under Namespace

Modules: State Classes: CompiledGraph, ParallelNode, StateGraph, TimeoutError

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.state_class_registryHash{String => Class}? (readonly)

Returns the current registry Hash, or nil when no class has been registered.

Returns:

  • (Hash{String => Class}, nil)


68
69
70
# File 'lib/phronomy.rb', line 68

def state_class_registry
  @state_class_registry
end

Class Method Details

.register_state_class(*classes) ⇒ Object

Register one or more State classes that are allowed to be deserialized by StateStore backends. When at least one class is registered, only registered classes will be accepted by +StateStore::Base#safe_state_class+.

Call this once at application startup (e.g. in a Rails initializer).

Examples:

Phronomy::Graph.register_state_class(MyWorkflowState, OtherState)

Parameters:

  • classes (Array<Class>)

    classes including Phronomy::Graph::State



56
57
58
59
60
61
62
63
64
# File 'lib/phronomy.rb', line 56

def register_state_class(*classes)
  @registry_mutex.synchronize do
    @state_class_registry ||= {}
    classes.each do |klass|
      raise ArgumentError, "#{klass.inspect} is not a Class" unless klass.is_a?(Class)
      @state_class_registry[klass.name] = klass
    end
  end
end

.reset_state_class_registry!Object

Clears the registry. Primarily used in tests.



71
72
73
# File 'lib/phronomy.rb', line 71

def reset_state_class_registry!
  @registry_mutex.synchronize { @state_class_registry = nil }
end