Class: Bosh::Director::Jobs::RunErrand

Inherits:
BaseJob show all
Includes:
LockHelper
Defined in:
lib/bosh/director/jobs/run_errand.rb

Instance Attribute Summary

Attributes inherited from BaseJob

#task_id

Class Method Summary collapse

Instance Method Summary collapse

Methods included from LockHelper

#with_compile_lock, #with_deployment_lock, #with_release_lock, #with_release_locks, #with_stemcell_lock

Methods inherited from BaseJob

#begin_stage, #event_log, #logger, perform, #result_file, #single_step_stage, #task_checkpoint, #track_and_log

Constructor Details

#initialize(deployment_name, errand_name) ⇒ RunErrand

Returns a new instance of RunErrand.



13
14
15
16
17
18
19
20
21
22
# File 'lib/bosh/director/jobs/run_errand.rb', line 13

def initialize(deployment_name, errand_name)
  @deployment_name = deployment_name
  @errand_name = errand_name
  @deployment_manager = Api::DeploymentManager.new
  @instance_manager = Api::InstanceManager.new
  @blobstore = App.instance.blobstores.blobstore

  log_bundles_cleaner = LogBundlesCleaner.new(@blobstore, 60 * 60 * 24 * 10, logger) # 10 days
  @logs_fetcher = LogsFetcher.new(event_log, @instance_manager, log_bundles_cleaner, logger)
end

Class Method Details

.job_typeObject



9
10
11
# File 'lib/bosh/director/jobs/run_errand.rb', line 9

def self.job_type
  :run_errand
end

Instance Method Details

#performObject



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
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/bosh/director/jobs/run_errand.rb', line 24

def perform
  deployment_model = @deployment_manager.find_by_name(@deployment_name)
  manifest = Psych.load(deployment_model.manifest)
  deployment = DeploymentPlan::Planner.parse(manifest, event_log, {})

  job = deployment.job(@errand_name)
  if job.nil?
    raise JobNotFound, "Errand `#{@errand_name}' doesn't exist"
  end

  unless job.can_run_as_errand?
    raise RunErrandError,
          "Job `#{job.name}' is not an errand. To mark a job as an errand " +
            "set its lifecycle to 'errand' in the deployment manifest."
  end

  if job.instances.empty?
    raise InstanceNotFound, "Instance `#{@deployment_name}/#{@errand_name}/0' doesn't exist"
  end

  runner = Errand::Runner.new(job, result_file, @instance_manager, event_log, @logs_fetcher)

  cancel_blk = lambda {
    begin
      task_checkpoint
    rescue TaskCancelled => e
      runner.cancel
      raise e
    end
  }

  with_deployment_lock(deployment) do
    with_updated_instances(deployment, job) do
      logger.info('Starting to run errand')
      runner.run(&cancel_blk)
    end
  end
end

#task_cancelled?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/bosh/director/jobs/run_errand.rb', line 63

def task_cancelled?
  super unless @ignore_cancellation
end