Class: Bosh::Cli::TaskTracking::Task

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stage, name, index, progress, callbacks) ⇒ Task

Returns a new instance of Task.



120
121
122
123
124
125
126
127
# 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

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



115
116
117
# File 'lib/cli/task_tracking/stage_collection.rb', line 115

def error
  @error
end

#indexObject (readonly)

Returns the value of attribute index.



115
116
117
# File 'lib/cli/task_tracking/stage_collection.rb', line 115

def index
  @index
end

#nameObject (readonly)

Returns the value of attribute name.



115
116
117
# File 'lib/cli/task_tracking/stage_collection.rb', line 115

def name
  @name
end

#progressObject (readonly)

Returns the value of attribute progress.



115
116
117
# File 'lib/cli/task_tracking/stage_collection.rb', line 115

def progress
  @progress
end

#stageObject (readonly)

Returns the value of attribute stage.



115
116
117
# File 'lib/cli/task_tracking/stage_collection.rb', line 115

def stage
  @stage
end

#stateObject (readonly)

Returns the value of attribute state.



115
116
117
# File 'lib/cli/task_tracking/stage_collection.rb', line 115

def state
  @state
end

Instance Method Details

#==(other) ⇒ Object



140
141
142
143
# 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?Boolean

Returns:

  • (Boolean)


145
146
147
# File 'lib/cli/task_tracking/stage_collection.rb', line 145

def done?
  %w(failed finished).include?(@state)
end

#failed?Boolean

Returns:

  • (Boolean)


149
150
151
# File 'lib/cli/task_tracking/stage_collection.rb', line 149

def failed?
  @state == 'failed'
end

#finished?Boolean

Returns:

  • (Boolean)


153
154
155
# File 'lib/cli/task_tracking/stage_collection.rb', line 153

def finished?
  @state == 'finished'
end

#update_with_event(event) ⇒ Object



129
130
131
132
133
134
135
136
137
138
# 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