Class: Roby::TaskIndex
Overview
TaskIndex objects are used to maintain a set of tasks as classified sets, speeding up query operations. See Plan#task_index.
Instance Attribute Summary collapse
-
#by_model ⇒ Object
readonly
A model => ValueSet map of the tasks for each model.
-
#by_owner ⇒ Object
readonly
A peer => ValueSet map of tasks given their owner.
-
#by_state ⇒ Object
readonly
A state => ValueSet map of tasks given their state.
-
#repaired_tasks ⇒ Object
readonly
The set of tasks which have an event which is being repaired.
Instance Method Summary collapse
-
#add(task) ⇒ Object
Add a new task to this index.
-
#add_owner(task, new_owner) ⇒ Object
Updates the index to reflect that
new_ownernow ownstask. -
#initialize ⇒ TaskIndex
constructor
A new instance of TaskIndex.
-
#remove(task) ⇒ Object
Remove all references of
taskfrom the index. -
#remove_owner(task, peer) ⇒ Object
Updates the index to reflect that
peerno more ownstask. -
#set_state(task, new_state) ⇒ Object
Updates the index to reflect a change of state for
task.
Constructor Details
#initialize ⇒ TaskIndex
Returns a new instance of TaskIndex.
321 322 323 324 325 326 327 328 329 330 |
# File 'lib/roby/query.rb', line 321 def initialize @by_model = Hash.new { |h, k| h[k] = ValueSet.new } @by_state = Hash.new TaskMatcher::STATE_PREDICATES.each do |state_name| by_state[state_name] = ValueSet.new end @by_owner = Hash.new @task_state = Hash.new @repaired_tasks = ValueSet.new end |
Instance Attribute Details
#by_model ⇒ Object (readonly)
A model => ValueSet map of the tasks for each model
311 312 313 |
# File 'lib/roby/query.rb', line 311 def by_model @by_model end |
#by_owner ⇒ Object (readonly)
A peer => ValueSet map of tasks given their owner.
317 318 319 |
# File 'lib/roby/query.rb', line 317 def by_owner @by_owner end |
#by_state ⇒ Object (readonly)
A state => ValueSet map of tasks given their state. The state is a symbol in [:pending, :starting, :running, :finishing, :finished]
315 316 317 |
# File 'lib/roby/query.rb', line 315 def by_state @by_state end |
#repaired_tasks ⇒ Object (readonly)
The set of tasks which have an event which is being repaired
319 320 321 |
# File 'lib/roby/query.rb', line 319 def repaired_tasks @repaired_tasks end |
Instance Method Details
#add(task) ⇒ Object
Add a new task to this index
333 334 335 336 337 338 339 340 341 |
# File 'lib/roby/query.rb', line 333 def add(task) for klass in task.model.ancestors by_model[klass] << task end by_state[:pending?] << task for owner in task.owners add_owner(task, owner) end end |
#add_owner(task, new_owner) ⇒ Object
Updates the index to reflect that new_owner now owns task
344 345 346 |
# File 'lib/roby/query.rb', line 344 def add_owner(task, new_owner) (by_owner[new_owner] ||= ValueSet.new) << task end |
#remove(task) ⇒ Object
Remove all references of task from the index.
370 371 372 373 374 375 376 377 378 379 380 |
# File 'lib/roby/query.rb', line 370 def remove(task) for klass in task.model.ancestors by_model[klass].delete(task) end for state_set in by_state state_set.last.delete(task) end for owner in task.owners remove_owner(task, owner) end end |
#remove_owner(task, peer) ⇒ Object
Updates the index to reflect that peer no more owns task
349 350 351 352 353 354 355 356 |
# File 'lib/roby/query.rb', line 349 def remove_owner(task, peer) if set = by_owner[peer] set.delete(task) if set.empty? by_owner.delete(peer) end end end |
#set_state(task, new_state) ⇒ Object
Updates the index to reflect a change of state for task
359 360 361 362 363 364 365 366 367 |
# File 'lib/roby/query.rb', line 359 def set_state(task, new_state) for state_set in by_state state_set.last.delete(task) end by_state[new_state] << task if new_state == :success? || new_state == :failed? by_state[:finished?] << task end end |