Class: Bosh::Director::JobRunner

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

Instance Method Summary collapse

Constructor Details

#initialize(job_class, task_id) ⇒ JobRunner

Returns a new instance of JobRunner.

Parameters:

  • job_class (Class)

    Job class to instantiate and run

  • task_id (Integer)

    Existing task id



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/bosh/director/job_runner.rb', line 8

def initialize(job_class, task_id)
  unless job_class.kind_of?(Class) &&
    job_class <= Jobs::BaseJob
    raise DirectorError, "Invalid director job class '#{job_class}'"
  end

  @task_id = task_id
  setup_task_logging

  task_manager = Bosh::Director::Api::TaskManager.new

  @job_class = job_class
  @task_logger.info("Looking for task with task id #{@task_id}")
  @task = task_manager.find_task(@task_id)
  @task_logger.info("Found task #{@task.inspect}")
end

Instance Method Details

#run(*args) ⇒ Object

Runs director job



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/bosh/director/job_runner.rb', line 26

def run(*args)
  Config.current_job = nil

  @task_logger.info("Starting task: #{@task_id}")
  started_at = Time.now

  with_thread_name("task:#{@task_id}") { perform_job(*args) }

  duration = Duration.duration(Time.now - started_at)
  @task_logger.info("Task took #{duration} to process.")
end