Class: Bosh::Director::Api::TaskManager
- Defined in:
- lib/bosh/director/api/task_manager.rb
Instance Method Summary collapse
- #decompress(src, dst) ⇒ Object
-
#find_task(task_id) ⇒ Models::Task
Looks up director task in DB.
- #log_file(task, log_type) ⇒ Object
-
#task_to_hash(task) ⇒ Hash
Returns hash representation of the task.
Instance Method Details
#decompress(src, dst) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/bosh/director/api/task_manager.rb', line 46 def decompress(src, dst) # only decompress if log_file is missing and we have a compressed file return unless !File.file?(dst) && File.file?(src) File.open(dst, 'w') do |file| Zlib::GzipReader.open(src) do |gz| file.write gz.read end end FileUtils.rm(src) end |
#find_task(task_id) ⇒ Models::Task
Looks up director task in DB
10 11 12 13 14 15 16 |
# File 'lib/bosh/director/api/task_manager.rb', line 10 def find_task(task_id) task = Models::Task[task_id] if task.nil? raise TaskNotFound, "Task #{task_id} not found" end task end |
#log_file(task, log_type) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/bosh/director/api/task_manager.rb', line 34 def log_file(task, log_type) # Backward compatibility return task.output unless File.directory?(task.output) file = File.join(task.output, log_type) file_gz = [file, 'gz'].join('.') decompress(file_gz, file) file end |
#task_to_hash(task) ⇒ Hash
Returns hash representation of the task
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/bosh/director/api/task_manager.rb', line 21 def task_to_hash(task) { "id" => task.id, "state" => task.state, "description" => task.description, "timestamp" => task..to_i, "started_at" => task.started_at ? task.started_at.to_i: nil, "result" => task.result, "user" => task.username || "admin", "deployment" => task.deployment_name } end |