Class: Bosh::Director::Jobs::BaseJob

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#task_idObject

Returns the value of attribute task_id.



13
14
15
# File 'lib/bosh/director/jobs/base_job.rb', line 13

def task_id
  @task_id
end

Class Method Details

.job_typeObject

Raises:

  • (NotImplementedError)


5
6
7
# File 'lib/bosh/director/jobs/base_job.rb', line 5

def self.job_type
  raise NotImplementedError.new('Subclasses must return a symbol representing type')
end

.perform(task_id, *args) ⇒ Object



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

def self.perform(task_id, *args)
  Bosh::Director::JobRunner.new(self, task_id).run(*args)
end

Instance Method Details

#begin_stage(stage_name, n_steps) ⇒ Object



40
41
42
43
# File 'lib/bosh/director/jobs/base_job.rb', line 40

def begin_stage(stage_name, n_steps)
  event_log.begin_stage(stage_name, n_steps)
  logger.info(stage_name)
end

#event_logObject



19
20
21
# File 'lib/bosh/director/jobs/base_job.rb', line 19

def event_log
  @event_log ||= Config.event_log
end

#loggerObject



15
16
17
# File 'lib/bosh/director/jobs/base_job.rb', line 15

def logger
  @logger ||= Config.logger
end

#result_fileObject



23
24
25
# File 'lib/bosh/director/jobs/base_job.rb', line 23

def result_file
  @result_file ||= Config.result
end

#single_step_stage(stage_name) ⇒ Object



52
53
54
55
# File 'lib/bosh/director/jobs/base_job.rb', line 52

def single_step_stage(stage_name)
  begin_stage(stage_name, 1)
  track_and_log(stage_name, false) { yield }
end

#task_cancelled?Boolean

Returns Has task been cancelled?.

Returns:

  • (Boolean)

    Has task been cancelled?



28
29
30
31
32
# File 'lib/bosh/director/jobs/base_job.rb', line 28

def task_cancelled?
  return false if task_id.nil?
  task = task_manager.find_task(task_id)
  task && (task.state == 'cancelling' || task.state == 'timeout')
end

#task_checkpointObject



34
35
36
37
38
# File 'lib/bosh/director/jobs/base_job.rb', line 34

def task_checkpoint
  if task_cancelled?
    raise TaskCancelled, "Task #{task_id} cancelled"
  end
end

#track_and_log(task, log = true) ⇒ Object



45
46
47
48
49
50
# File 'lib/bosh/director/jobs/base_job.rb', line 45

def track_and_log(task, log = true)
  event_log.track(task) do |ticker|
    logger.info(task) if log
    yield ticker if block_given?
  end
end