Class: AcidicJob::WorkflowBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/acidic_job/workflow_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWorkflowBuilder

Returns a new instance of WorkflowBuilder.



7
8
9
# File 'lib/acidic_job/workflow_builder.rb', line 7

def initialize
  @steps = []
end

Instance Attribute Details

#stepsObject (readonly)

Returns the value of attribute steps.



5
6
7
# File 'lib/acidic_job/workflow_builder.rb', line 5

def steps
  @steps
end

Instance Method Details

#define_workflowObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/acidic_job/workflow_builder.rb', line 22

def define_workflow
  # [ { does: "step 1", awaits: [] }, { does: "step 2", awaits: [] }, ... ]
  @steps << { "does" => Run::FINISHED_RECOVERY_POINT.to_s }

  {}.tap do |workflow|
    @steps.each_cons(2).map do |enter_step, exit_step|
      enter_name = enter_step["does"]
      workflow[enter_name] = enter_step.merge("then" => exit_step["does"])
    end
  end
  # { "step 1": { does: "step 1", awaits: [], then: "step 2" }, ...  }
end

#step(method_name, awaits: [], for_each: nil) ⇒ Object Also known as:



11
12
13
14
15
16
17
18
19
# File 'lib/acidic_job/workflow_builder.rb', line 11

def step(method_name, awaits: [], for_each: nil)
  @steps << {
    "does" => method_name.to_s,
    "awaits" => awaits,
    "for_each" => for_each
  }

  @steps
end