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, progress, callbacks) ⇒ Task

Returns a new instance of Task.



120
121
122
123
124
125
126
# File 'lib/cli/task_tracking/stage_collection.rb', line 120

def initialize(stage, name, progress, callbacks)
  @stage = stage
  @name = name
  @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

#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



139
140
141
142
# File 'lib/cli/task_tracking/stage_collection.rb', line 139

def ==(other)
  return false unless other.is_a?(Task)
  [stage, name] == [other.stage, other.name]
end

#done?Boolean

Returns:

  • (Boolean)


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

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

#failed?Boolean

Returns:

  • (Boolean)


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

def failed?
  @state == 'failed'
end

#finished?Boolean

Returns:

  • (Boolean)


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

def finished?
  @state == 'finished'
end

#update_with_event(event) ⇒ Object



128
129
130
131
132
133
134
135
136
137
# File 'lib/cli/task_tracking/stage_collection.rb', line 128

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