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
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/bosh/director/api/task_manager.rb', line 51 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
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/bosh/director/api/task_manager.rb', line 32 def log_file(task, log_type) # Backward compatibility return task.output unless File.directory?(task.output) # Backward compatbility from renaming `soap` log to `cpi` log. # Old tasks might have been written to the file `soap` and we should # still return them if log_type = cpi. Same goes for new task logs # written to `cpi` but an old CLI has requested log_type = soap. if %w(soap cpi).include?(log_type) log_type = File.file?(File.join(task.output, "soap")) ? "soap" : "cpi" end 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 |
# 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, "result" => task.result, "user" => task.user ? task.user.username : "admin" } end |