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.



17
18
19
# File 'lib/bosh/director/jobs/base_job.rb', line 17

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

.schedule_messageObject



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

def self.schedule_message
  "scheduled #{name.split('::').last}"
end

Instance Method Details

#begin_stage(stage_name, n_steps) ⇒ Object



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

def begin_stage(stage_name, n_steps)
  @event_log_stage = Config.event_log.begin_stage(stage_name, n_steps)
  logger.info(stage_name)
end

#dns_managerObject



27
28
29
# File 'lib/bosh/director/jobs/base_job.rb', line 27

def dns_manager
  @dns_manager ||= DnsManagerProvider.create
end

#event_managerObject



65
66
67
# File 'lib/bosh/director/jobs/base_job.rb', line 65

def event_manager
  @event_manager ||= Api::EventManager.new(Config.record_events)
end

#loggerObject



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

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



56
57
58
59
# File 'lib/bosh/director/jobs/base_job.rb', line 56

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?



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

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

#task_checkpointObject



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

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

#track_and_log(task, log = true) ⇒ Object



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

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

#usernameObject



61
62
63
# File 'lib/bosh/director/jobs/base_job.rb', line 61

def username
  @user ||= task_manager.find_task(task_id).username
end