Class: Bosh::Director::Errand::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh/director/errand/runner.rb

Defined Under Namespace

Classes: ErrandResult

Instance Method Summary collapse

Constructor Details

#initialize(job, result_file, instance_manager, event_log) ⇒ Runner

Returns a new instance of Runner.



43
44
45
46
47
48
# File 'lib/bosh/director/errand/runner.rb', line 43

def initialize(job, result_file, instance_manager, event_log)
  @job = job
  @result_file = result_file
  @instance_manager = instance_manager
  @event_log = event_log
end

Instance Method Details

#runString

Runs errand on job instances

Returns:

  • (String)

    short description of the errand result



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/bosh/director/errand/runner.rb', line 52

def run
  instance = @job.instances.first
  unless instance
    raise DirectorError, 'Must have at least one job instance to run an errand'
  end

  agent_task_result = nil

  event_log_stage = @event_log.begin_stage('Running errand', 1)
  event_log_stage.advance_and_track("#{@job.name}/#{instance.index}") do
    agent = @instance_manager.agent_client_for(instance.model)
    agent_task_result = agent.run_errand
  end

  errand_result = ErrandResult.from_agent_task_result(agent_task_result)
  @result_file.write(JSON.dump(errand_result.to_hash) + "\n")

  title_prefix = "Errand `#{@job.name}' completed"
  exit_code_suffix = "(exit code #{errand_result.exit_code})"

  if errand_result.exit_code == 0
    "#{title_prefix} successfully #{exit_code_suffix}"
  else
    "#{title_prefix} with error #{exit_code_suffix}"
  end
end