Class: Bosh::Cli::DirectorTask

Inherits:
Object
  • Object
show all
Defined in:
lib/cli/director_task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(director, task_id, log_type = nil) ⇒ DirectorTask

Returns a new instance of DirectorTask


5
6
7
8
9
10
11
# File 'lib/cli/director_task.rb', line 5

def initialize(director, task_id, log_type = nil)
  @director = director
  @task_id = task_id
  @offset = 0
  @log_type = log_type
  @buf = ""
end

Instance Attribute Details

#offsetObject

Returns the value of attribute offset


3
4
5
# File 'lib/cli/director_task.rb', line 3

def offset
  @offset
end

Instance Method Details

#cancelObject


53
54
55
# File 'lib/cli/director_task.rb', line 53

def cancel
  @director.cancel_task(@task_id)
end

#flush_outputObject


47
48
49
50
51
# File 'lib/cli/director_task.rb', line 47

def flush_output
  out = @buf
  @buf = ""
  out.blank? ? nil : "#{out}\n"
end

#outputObject


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cli/director_task.rb', line 21

def output
  body, new_offset = @director.get_task_output(@task_id, @offset, @log_type)

  @buf << body if body

  if new_offset
    @offset = new_offset
  else
    return flush_output
  end

  last_nl = @buf.rindex("\n")

  if last_nl.nil?
    result = nil
  elsif last_nl != @buf.size - 1
    result = @buf[0..last_nl]
    @buf = @buf[last_nl+1..-1]
  else
    result = @buf
    @buf = ""
  end

  result
end

#resultObject


17
18
19
# File 'lib/cli/director_task.rb', line 17

def result
  @director.get_task_result(@task_id)
end

#stateObject


13
14
15
# File 'lib/cli/director_task.rb', line 13

def state
  @director.get_task_state(@task_id)
end