Class: Kuroko2::Workflow::Task::Fork

Inherits:
Base
  • Object
show all
Defined in:
lib/autoload/kuroko2/workflow/task/fork.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Kuroko2::Workflow::Task::Base

Instance Method Details

#executeObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/autoload/kuroko2/workflow/task/fork.rb', line 5

def execute
  children = token.children
  if children.empty?
    message = "(token #{token.uuid}) Start to fork."

    token.job_instance.logs.info(message)
    Kuroko2.logger.info(message)

    node.children.each do |child|
      attributes = token.attributes.except('id', 'uuid', 'script', 'path', 'message', 'created_at', 'updated_at')
      attributes = attributes.merge(uuid: SecureRandom.uuid, parent: token, script: child.to_script, path: '/')

      Token.create!(attributes).tap do |created|
        message = "(token #{created.uuid}) New token are created for #{node.path}"
        created.job_instance.logs.info(message)

        Kuroko2.logger.info(message)
      end
    end
    :pass
  elsif children.all?(&:finished?)
    message = "(token #{token.uuid}) All children are finished."

    token.job_instance.logs.info(message)
    Kuroko2.logger.info(message)

    :next_sibling
  else
    :pass
  end
end

#validateObject



37
38
39
40
41
# File 'lib/autoload/kuroko2/workflow/task/fork.rb', line 37

def validate
  if node.children.empty?
    raise Workflow::AssertionError, "Fork must have children node"
  end
end