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
Backup, CleanupArtifacts, CloudCheck::ApplyResolutions, CloudCheck::Scan, CloudCheck::ScanAndFix, CreateSnapshot, DeleteDeployment, DeleteDeploymentSnapshots, DeleteOrphanDisks, DeleteRelease, DeleteSnapshots, DeleteStemcell, ExportRelease, FetchLogs, RunErrand, ScheduledBackup, 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
48
49
50
51
|
# File 'lib/bosh/director/jobs/base_job.rb', line 48
def begin_stage(stage_name, n_steps)
event_log.begin_stage(stage_name, n_steps)
logger.info(stage_name)
end
|
#event_log ⇒ Object
23
24
25
|
# File 'lib/bosh/director/jobs/base_job.rb', line 23
def event_log
@event_log ||= Config.event_log
end
|
19
20
21
|
# File 'lib/bosh/director/jobs/base_job.rb', line 19
def logger
@logger ||= Config.logger
end
|
#result_file ⇒ Object
27
28
29
|
# File 'lib/bosh/director/jobs/base_job.rb', line 27
def result_file
@result_file ||= Config.result
end
|
#single_step_stage(stage_name) ⇒ Object
60
61
62
63
|
# File 'lib/bosh/director/jobs/base_job.rb', line 60
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?.
36
37
38
39
40
|
# File 'lib/bosh/director/jobs/base_job.rb', line 36
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
42
43
44
45
46
|
# File 'lib/bosh/director/jobs/base_job.rb', line 42
def task_checkpoint
if task_cancelled?
raise TaskCancelled, "Task #{task_id} cancelled"
end
end
|
#track_and_log(task, log = true) ⇒ Object
53
54
55
56
57
58
|
# File 'lib/bosh/director/jobs/base_job.rb', line 53
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
|