Module: SolidFlow::Idempotency

Defined in:
lib/solid_flow/idempotency.rb

Class Method Summary collapse

Class Method Details

.default(execution_id, step_name, attempt = 0) ⇒ Object



26
27
28
# File 'lib/solid_flow/idempotency.rb', line 26

def default(execution_id, step_name, attempt = 0)
  Digest::SHA256.hexdigest([execution_id, step_name, attempt].join(":"))
end

.digest(*parts) ⇒ Object



30
31
32
# File 'lib/solid_flow/idempotency.rb', line 30

def digest(*parts)
  Digest::SHA256.hexdigest(parts.flatten.compact.map(&:to_s).join("|"))
end

.evaluate(key, workflow:, step:) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/solid_flow/idempotency.rb', line 9

def evaluate(key, workflow:, step:)
  case key
  when Proc
    workflow.instance_exec(&key).to_s
  when Symbol
    workflow.public_send(key).to_s
  when String
    key
  when Array
    key.compact.map(&:to_s).join(":")
  when nil
    default(workflow.execution.id, step.name)
  else
    key.to_s
  end
end