class Bosh::Cli::TaskTracking::Stage

Attributes

name[R]
tags[R]
tasks[R]
total[R]

Public Class Methods

new(name, tags, total, callbacks) click to toggle source
# 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

Public Instance Methods

==(other) click to toggle source
# 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
duration() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

all_tasks_done?() click to toggle source
# File lib/cli/task_tracking/stage_collection.rb, line 97
def all_tasks_done?
  tasks.all? { |t| t.done? }
end
all_tasks_finished?() click to toggle source
# File lib/cli/task_tracking/stage_collection.rb, line 101
def all_tasks_finished?
  tasks.all? { |t| t.finished? }
end
any_tasks_failed?() click to toggle source
# File lib/cli/task_tracking/stage_collection.rb, line 105
def any_tasks_failed?
  tasks.any? { |t| t.failed? }
end
failed?(event) click to toggle source
# File lib/cli/task_tracking/stage_collection.rb, line 93
def failed?(event)
  seen_all_tasks?(event) && all_tasks_done? && any_tasks_failed?
end
finished?(event) click to toggle source
# File lib/cli/task_tracking/stage_collection.rb, line 89
def finished?(event)
  seen_all_tasks?(event) && all_tasks_finished?
end
fire_failed_callback() click to toggle source
# File lib/cli/task_tracking/stage_collection.rb, line 80
def fire_failed_callback
  callback = @callbacks[:stage_failed]
  callback.call(self) if callback
end
fire_finished_callback() click to toggle source
# File lib/cli/task_tracking/stage_collection.rb, line 75
def fire_finished_callback
  callback = @callbacks[:stage_finished]
  callback.call(self) if callback
end
fire_started_callback() click to toggle source
# File lib/cli/task_tracking/stage_collection.rb, line 70
def fire_started_callback
  callback = @callbacks[:stage_started]
  callback.call(self) if callback
end
seen_all_tasks?(event) click to toggle source
# File lib/cli/task_tracking/stage_collection.rb, line 109
def seen_all_tasks?(event)
  tasks.size == event['total'] || event['total'].nil?
end
started?() click to toggle source
# File lib/cli/task_tracking/stage_collection.rb, line 85
def started?
  @started = true if !@started
end