Sha256: 3830bb12e21cd9c85599d4f8d299f29092e05c0b8a3e18b1e6a81a871334b2c0

Contents?: true

Size: 1006 Bytes

Versions: 1

Compression:

Stored size: 1006 Bytes

Contents

module Novel
  class WorkflowBuilder
    attr_reader :name, :raw_workflow, :repository

    def initialize(name:, repository:, raw_workflow: [])
      @name = name
      @raw_workflow = raw_workflow
      @repository = repository
    end

    def register_step(name, activity:, compensation: nil)
      self.class.new(
        name: name,
        repository: repository,
        raw_workflow: raw_workflow + [{ name: name, activity: activity, compensation: compensation }]
      )
    end

    def build
      Saga.new(
        name: name,
        workflow: Workflow.new(raw: raw_workflow),
        executor: Executor.new(container: build_container, repository: repository)
      )
    end

  private

    def build_container
      container = Container.new
      raw_workflow.each do |step|
        container.register("#{step[:name]}.activity", step[:activity][:command])
        container.register("#{step[:name]}.compensation", step[:compensation][:command])
      end
      container
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
novel-0.3.0 lib/novel/workflow_builder.rb