Module: SolidFlow::Determinism
- Defined in:
- lib/solid_flow/determinism.rb
Class Method Summary collapse
- .assert_graph!(workflow_class, persisted_signature) ⇒ Object
- .graph_signature(workflow_class) ⇒ Object
Class Method Details
.assert_graph!(workflow_class, persisted_signature) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/solid_flow/determinism.rb', line 30 def assert_graph!(workflow_class, persisted_signature) signature = graph_signature(workflow_class) return signature unless persisted_signature return signature if signature == persisted_signature raise Errors::NonDeterministicWorkflowError.new(expected: persisted_signature, actual: signature) end |
.graph_signature(workflow_class) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/solid_flow/determinism.rb', line 9 def graph_signature(workflow_class) payload = { workflow: workflow_class.name, steps: workflow_class.steps.map do |step| { name: step.name, task: step.task, block: step.block? ? "block" : nil, retry: step.retry_policy, timeouts: step.timeouts, options: step. } end, signals: workflow_class.signals.keys.map(&:to_s).sort, queries: workflow_class.queries.keys.map(&:to_s).sort, compensations: workflow_class.compensations.transform_keys(&:to_s).transform_values(&:to_s).sort.to_h } Digest::SHA256.hexdigest(JSON.generate(payload)) end |