Class: MigrateTasksFromDeadNodeJob

Inherits:
ContainerBrokerBaseJob show all
Defined in:
app/jobs/migrate_tasks_from_dead_node_job.rb

Constant Summary

Constants inherited from ContainerBrokerBaseJob

ContainerBrokerBaseJob::JOB_METRIC

Instance Method Summary collapse

Methods inherited from ContainerBrokerBaseJob

request_id_from_args

Instance Method Details

#perform(node:) ⇒ Object



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
# File 'app/jobs/migrate_tasks_from_dead_node_job.rb', line 6

def perform(node:)
  if node.available?
    Rails.logger.debug("Not migrating tasks because #{node} returned to available status")
    return
  end

  node.run_with_lock_no_wait do
    Rails.logger.debug("Migrating tasks from #{node}")
    node.slots.reject(&:available?).each do |slot|
      Rails.logger.debug("Migrating task for #{slot}")
      current_task = slot.current_task
      if current_task
        Rails.logger.debug("Retrying slot current task #{current_task}")
        current_task.mark_as_retry if current_task.starting? || current_task.started?
      else
        Rails.logger.debug("Slot does not have current task")
      end

      MigrateRunner.new(runner_id: slot.runner_id).migrate

      Rails.logger.debug("Releasing #{slot}")
      slot.release
      Rails.logger.debug("#{slot} released")
    end
  end
end