Class: CircleCI::Parallel::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/circleci/parallel/node.rb

Overview

Represents a CircleCI node.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(build, index) ⇒ Node

Returns a new instance of Node.

Parameters:

  • build (Build)

    the build that the node belongs to

  • index (Integer)

    node index (CIRCLE_NODE_INDEX)



9
10
11
12
# File 'lib/circleci/parallel/node.rb', line 9

def initialize(build, index)
  @build = build
  @index = index
end

Instance Attribute Details

#buildObject (readonly)

Returns the value of attribute build.



5
6
7
# File 'lib/circleci/parallel/node.rb', line 5

def build
  @build
end

#indexObject (readonly)

Returns the value of attribute index.



5
6
7
# File 'lib/circleci/parallel/node.rb', line 5

def index
  @index
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



14
15
16
# File 'lib/circleci/parallel/node.rb', line 14

def ==(other)
  build == other.build && index == other.index
end

#data_dirString

Returns the local data directory where node specific data should be saved in.

Returns:

  • (String)

    the local data directory where node specific data should be saved in

See Also:



38
39
40
# File 'lib/circleci/parallel/node.rb', line 38

def data_dir
  File.join(BASE_DATA_DIR, ssh_host)
end

#hashObject



20
21
22
# File 'lib/circleci/parallel/node.rb', line 20

def hash
  build.hash ^ index.hash
end

#master?Boolean

Returns whether the node is the master node or not.

Returns:

  • (Boolean)

    whether the node is the master node or not



25
26
27
# File 'lib/circleci/parallel/node.rb', line 25

def master?
  index.zero?
end

#other_nodesArray<Node>

Returns other nodes of the same build.

Returns:

  • (Array<Node>)

    other nodes of the same build



43
44
45
# File 'lib/circleci/parallel/node.rb', line 43

def other_nodes
  @other_nodes ||= (build.nodes - [self]).freeze
end

#ssh_hostString

Returns the hostname that can be used for ssh command to connect between nodes.

Returns:

  • (String)

    the hostname that can be used for ssh command to connect between nodes



30
31
32
33
# File 'lib/circleci/parallel/node.rb', line 30

def ssh_host
  # https://circleci.com/docs/ssh-between-build-containers/
  "node#{index}"
end