Class: Bosh::Director::Jobs::BaseJob
- Inherits:
-
Object
- Object
- Bosh::Director::Jobs::BaseJob
show all
- Defined in:
- lib/bosh/director/jobs/base_job.rb
Direct Known Subclasses
AttachDisk, Backup, CleanupArtifacts, CloudCheck::ApplyResolutions, CloudCheck::Scan, CloudCheck::ScanAndFix, CreateSnapshot, DeleteDeployment, DeleteDeploymentSnapshots, DeleteOrphanDisks, DeleteRelease, DeleteSnapshots, DeleteStemcell, DeleteVm, ExportRelease, FetchLogs, RunErrand, ScheduledBackup, ScheduledEventsCleanup, ScheduledOrphanCleanup, SnapshotDeployment, SnapshotDeployments, SnapshotSelf, Ssh, UpdateDeployment, UpdateRelease, UpdateStemcell, VmState
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
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
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
|
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_message ⇒ Object
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
|
19
20
21
|
# File 'lib/bosh/director/jobs/base_job.rb', line 19
def logger
@logger ||= Config.logger
end
|
#result_file ⇒ Object
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?.
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_checkpoint ⇒ Object
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
|
61
62
63
|
# File 'lib/bosh/director/jobs/base_job.rb', line 61
def username
@user ||= task_manager.find_task(task_id).username
end
|