Class: Bosh::Cli::TaskTracking::Stage

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, tags, total, callbacks) ⇒ Stage

Returns a new instance of Stage.



24
25
26
27
28
29
30
# File 'lib/cli/task_tracking/stage_collection.rb', line 24

def initialize(name, tags, total, callbacks)
  @name = name
  @tags = Array(tags)
  @total = total
  @callbacks = callbacks
  @tasks = []
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



22
23
24
# File 'lib/cli/task_tracking/stage_collection.rb', line 22

def name
  @name
end

#tagsObject (readonly)

Returns the value of attribute tags.



22
23
24
# File 'lib/cli/task_tracking/stage_collection.rb', line 22

def tags
  @tags
end

#tasksObject (readonly)

Returns the value of attribute tasks.



22
23
24
# File 'lib/cli/task_tracking/stage_collection.rb', line 22

def tasks
  @tasks
end

#totalObject (readonly)

Returns the value of attribute total.



22
23
24
# File 'lib/cli/task_tracking/stage_collection.rb', line 22

def total
  @total
end

Instance Method Details

#==(other) ⇒ Object



63
64
65
66
# File 'lib/cli/task_tracking/stage_collection.rb', line 63

def ==(other)
  return false unless other.is_a?(Stage)
  [name, tags, total] == [other.name, other.tags, other.total]
end

#durationObject



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/cli/task_tracking/stage_collection.rb', line 45

def duration
  total_duration = TotalDuration.new

  task_start_times = @tasks.map(&:started_at)
  task_end_times = @tasks.map(&:finished_at)

  # If any task start time is nil, the start time for the entire stage is unknown.
  total_duration.started_at = task_start_times.min unless task_start_times.include?(nil)
  total_duration.finished_at = task_end_times.max unless task_end_times.include?(nil)

  total_duration.duration
end

#similar?(other) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
61
# File 'lib/cli/task_tracking/stage_collection.rb', line 58

def similar?(other)
  return false unless other.is_a?(Stage)
  name == other.name
end

#update_with_event(event) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/cli/task_tracking/stage_collection.rb', line 32

def update_with_event(event)
  new_task = Task.new(self, event['task'], event['index'], event['progress'], @callbacks)
  unless found_task = @tasks.find { |s| s == new_task }
    found_task = new_task
    @tasks << new_task
  end
  fire_started_callback if started?
  found_task.update_with_event(event)
  fire_finished_callback if finished?(event)
  fire_failed_callback if failed?(event)
  found_task
end