class Novel::Executor

Attributes

activity_flow_executor[R]
compensation_flow_executor[R]
container[R]
repository[R]

Public Class Methods

new(container:, repository:) click to toggle source
# File lib/novel/executor.rb, line 10
def initialize(container:, repository:)
  @container = container
  @repository = repository

  @activity_flow_executor = Novel::Executor::ActivityFlow.new(container: container, repository: repository)
  @compensation_flow_executor = Novel::Executor::CompensationFlow.new(container: container, repository: repository)
end

Public Instance Methods

call_activity_flow(context, state_machine, steps) click to toggle source
# File lib/novel/executor.rb, line 31
def call_activity_flow(context, state_machine, steps)
  activity_flow_executor.call(context, state_machine, steps)
end
call_compensation_flow(context, state_machine, steps) click to toggle source
# File lib/novel/executor.rb, line 35
def call_compensation_flow(context, state_machine, steps)
  compensation_flow_executor.call(context, state_machine, steps)
end
finish_transaction(context, state_machine) click to toggle source
# File lib/novel/executor.rb, line 39
def finish_transaction(context, state_machine)
end
start_transaction(saga_id, params, first_step) click to toggle source
# File lib/novel/executor.rb, line 18
def start_transaction(saga_id, params, first_step)
  context = repository.find_or_create_context(saga_id, params)
  state_machine = StateMachines::SagaStatus.build(state: context.saga_status)

  if state_machine.started?
    state_machine.wait
    repository.persist_context(context, saga_status: state_machine.state)
    return Success(status: :waiting, context: context) if first_step[:async]
  end

  Success(status: :pending, context: [context, state_machine])
end