Class: Novel::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/novel/executor.rb,
lib/novel/executor/activity_flow.rb,
lib/novel/executor/compensation_flow.rb

Defined Under Namespace

Classes: ActivityFlow, CompensationFlow

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(container:, repository:) ⇒ Executor

Returns a new instance of Executor.



10
11
12
13
14
15
16
# 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

Instance Attribute Details

#activity_flow_executorObject (readonly)

Returns the value of attribute activity_flow_executor.



8
9
10
# File 'lib/novel/executor.rb', line 8

def activity_flow_executor
  @activity_flow_executor
end

#compensation_flow_executorObject (readonly)

Returns the value of attribute compensation_flow_executor.



8
9
10
# File 'lib/novel/executor.rb', line 8

def compensation_flow_executor
  @compensation_flow_executor
end

#containerObject (readonly)

Returns the value of attribute container.



8
9
10
# File 'lib/novel/executor.rb', line 8

def container
  @container
end

#repositoryObject (readonly)

Returns the value of attribute repository.



8
9
10
# File 'lib/novel/executor.rb', line 8

def repository
  @repository
end

Instance Method Details

#call_activity_flow(context, state_machine, steps) ⇒ Object



31
32
33
# 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) ⇒ Object



35
36
37
# 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) ⇒ Object



39
40
# File 'lib/novel/executor.rb', line 39

def finish_transaction(context, state_machine)
end

#start_transaction(saga_id, params, first_step) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# 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