Class: SidekiqWorkflows::WorkerNode

Inherits:
Object
  • Object
show all
Includes:
Node
Defined in:
lib/sidekiq_workflows/worker_node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Node

#add_group, #all_nodes, #serialize

Constructor Details

#initialize(workers:, workflow_uuid: nil, on_partial_complete: nil, parent: nil) ⇒ WorkerNode

Returns a new instance of WorkerNode.



12
13
14
15
16
17
18
19
20
21
# File 'lib/sidekiq_workflows/worker_node.rb', line 12

def initialize(workers:, workflow_uuid: nil, on_partial_complete: nil, parent: nil)
  @workers = workers.each do |entry|
    entry[:worker] = ActiveSupport::Inflector.constantize(entry[:worker]) if entry[:worker].is_a?(String)
    entry[:delay] = entry[:delay].to_i if entry[:delay]
  end
  @workflow_uuid = workflow_uuid
  @on_partial_complete = on_partial_complete
  @parent = parent
  @children = []
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



9
10
11
# File 'lib/sidekiq_workflows/worker_node.rb', line 9

def children
  @children
end

#on_partial_completeObject

Returns the value of attribute on_partial_complete.



8
9
10
# File 'lib/sidekiq_workflows/worker_node.rb', line 8

def on_partial_complete
  @on_partial_complete
end

#parentObject (readonly)

Returns the value of attribute parent.



10
11
12
# File 'lib/sidekiq_workflows/worker_node.rb', line 10

def parent
  @parent
end

#workersObject

Returns the value of attribute workers.



8
9
10
# File 'lib/sidekiq_workflows/worker_node.rb', line 8

def workers
  @workers
end

#workflow_uuidObject

Returns the value of attribute workflow_uuid.



8
9
10
# File 'lib/sidekiq_workflows/worker_node.rb', line 8

def workflow_uuid
  @workflow_uuid
end

Instance Method Details

#to_hObject



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

def to_h
  {
    workers: workers.map do |entry|
      {
        worker: entry[:worker].name,
        payload: entry[:payload],
        delay: entry[:delay]
      }
    end,
    workflow_uuid: workflow_uuid,
    on_partial_complete: on_partial_complete,
    children: @children.map(&:to_h)
  }
end