Class: Simplekiq::Orchestration

Inherits:
Object
  • Object
show all
Defined in:
lib/simplekiq/orchestration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOrchestration

Returns a new instance of Orchestration.



6
7
8
# File 'lib/simplekiq/orchestration.rb', line 6

def initialize
  @serial_workflow = []
end

Instance Attribute Details

#parallel_workflowObject

Returns the value of attribute parallel_workflow.



5
6
7
# File 'lib/simplekiq/orchestration.rb', line 5

def parallel_workflow
  @parallel_workflow
end

#serial_workflowObject

Returns the value of attribute serial_workflow.



5
6
7
# File 'lib/simplekiq/orchestration.rb', line 5

def serial_workflow
  @serial_workflow
end

Instance Method Details

#in_parallelObject



15
16
17
18
19
20
21
22
# File 'lib/simplekiq/orchestration.rb', line 15

def in_parallel
  @parallel_workflow = []
  yield
  serial_workflow << @parallel_workflow if @parallel_workflow.any?
ensure
  @parallel_workflow = nil
  serial_workflow
end

#run(*step) ⇒ Object



10
11
12
13
# File 'lib/simplekiq/orchestration.rb', line 10

def run(*step)
  workflow = parallel_workflow || serial_workflow
  workflow << step
end

#serialized_workflowObject



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/simplekiq/orchestration.rb', line 24

def serialized_workflow
  @serialized_workflow ||= serial_workflow.map do |step|
    case step[0]
    when Array
      step.map do |(job, *args)|
        {"klass" => job.name, "args" => args}
      end
    when Class
      job, *args = step
      {"klass" => job.name, "args" => args}
    end
  end
end