class Bosh::Cli::TaskTracking::Task

Attributes

error[R]
index[R]
name[R]
progress[R]
stage[R]
state[R]

Public Class Methods

new(stage, name, index, progress, callbacks) click to toggle source
# File lib/cli/task_tracking/stage_collection.rb, line 120
def initialize(stage, name, index, progress, callbacks)
  @stage = stage
  @name = name
  @index = index
  @progress = progress
  @callbacks = callbacks
  @total_duration = TotalDuration.new
end

Public Instance Methods

==(other) click to toggle source
# File lib/cli/task_tracking/stage_collection.rb, line 140
def ==(other)
  return false unless other.is_a?(Task)
  [stage, index, name] == [other.stage, other.index, other.name]
end
done?() click to toggle source
# File lib/cli/task_tracking/stage_collection.rb, line 145
def done?
  %w(failed finished).include?(@state)
end
failed?() click to toggle source
# File lib/cli/task_tracking/stage_collection.rb, line 149
def failed?
  @state == 'failed'
end
finished?() click to toggle source
# File lib/cli/task_tracking/stage_collection.rb, line 153
def finished?
  @state == 'finished'
end
update_with_event(event) click to toggle source
# File lib/cli/task_tracking/stage_collection.rb, line 129
def update_with_event(event)
  @state    = event['state']
  @progress = event['progress']
  @error    = (event['data'] || {})['error']

  @total_duration.started_at  = event['time'] if @state == 'started'
  @total_duration.finished_at = event['time'] if @state == 'finished' || @state == 'failed'

  call_state_callback
end

Private Instance Methods

call_state_callback() click to toggle source
# File lib/cli/task_tracking/stage_collection.rb, line 159
def call_state_callback
  callback = case @state
    when 'started'  then @callbacks[:task_started]
    when 'finished' then @callbacks[:task_finished]
    when 'failed'   then @callbacks[:task_failed]
  end
  callback.call(self) if callback
end