Class: Runners::Docker::UpdateNodeStatus

Inherits:
Object
  • Object
show all
Includes:
UpdateNodeStatusHelper
Defined in:
app/services/runners/docker/update_node_status.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from UpdateNodeStatusHelper

#check_slot_release, #remove_unknown_runner, #send_metrics

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



8
9
10
# File 'app/services/runners/docker/update_node_status.rb', line 8

def node
  @node
end

Instance Method Details

#perform(node:) ⇒ Object



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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/services/runners/docker/update_node_status.rb', line 10

def perform(node:)
  @node = node
  Rails.logger.debug("Start updating node status for #{node}")

  # Other tasks can be started at this time. Because of this it's necessary to load the tasks first and then the containers
  started_tasks = Task.started.where(:slot.in => node.slots.pluck(:id)).to_a

  Rails.logger.debug("Got #{containers.count} containers")

  execution_infos = containers.map do |container|
    execution_info = CreateExecutionInfo.new.perform(container: container)

    slot = node.slots.find_by(runner_id: execution_info.id)
    if slot
      Rails.logger.debug("Slot found for container #{execution_info.id}: #{slot}")

      if execution_info.terminated?
        Rails.logger.debug("Container #{execution_info.id} exited")

        check_slot_release(slot: slot, runner_id: execution_info.id)
      elsif started_with_error?(container: container, docker_connection: CreateConnection.new.perform(node: node))
        container.start
      end
    else
      remove_unknown_runner(node: node, runner_id: execution_info.id)
    end

    execution_info
  end

  RescheduleTasksForMissingRunners
    .new(runner_ids: execution_infos.map(&:id), started_tasks: started_tasks)
    .perform

  node.register_success

  send_metrics(node: node, execution_infos: execution_infos)
rescue Excon::Error, ::Docker::Error::DockerError => e
  node.register_error(e.message)
end