Class: Fasten::TaskManager

Inherits:
Array
  • Object
show all
Defined in:
lib/fasten/task_manager.rb

Overview

rubocop:disable Metrics/ClassLength

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runner:, targets: []) ⇒ TaskManager

Returns a new instance of TaskManager.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/fasten/task_manager.rb', line 5

def initialize(runner:, targets: [])
  super()

  @map = {}
  @done = []
  @failed = []
  @pending = []
  @running = []
  @targets = targets
  @waiting = nil
  @runner = runner
end

Instance Attribute Details

#doneObject (readonly)

Returns the value of attribute done.



3
4
5
# File 'lib/fasten/task_manager.rb', line 3

def done
  @done
end

#failedObject (readonly)

Returns the value of attribute failed.



3
4
5
# File 'lib/fasten/task_manager.rb', line 3

def failed
  @failed
end

#pendingObject (readonly)

Returns the value of attribute pending.



3
4
5
# File 'lib/fasten/task_manager.rb', line 3

def pending
  @pending
end

#runnerObject (readonly)

Returns the value of attribute runner.



3
4
5
# File 'lib/fasten/task_manager.rb', line 3

def runner
  @runner
end

#runningObject (readonly)

Returns the value of attribute running.



3
4
5
# File 'lib/fasten/task_manager.rb', line 3

def running
  @running
end

#targetsObject (readonly)

Returns the value of attribute targets.



3
4
5
# File 'lib/fasten/task_manager.rb', line 3

def targets
  @targets
end

Instance Method Details

#<<(task) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/fasten/task_manager.rb', line 26

def <<(task)
  raise "Object class #{task.class} not allowed" unless task.is_a? Task
  raise "Task '#{task.name}' already defined" if @map[task.name]

  @map[task.name] = task
  @waiting = nil
  super
end

#failed?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/fasten/task_manager.rb', line 78

def failed?
  !failed.empty?
end

#nextObject



35
36
37
# File 'lib/fasten/task_manager.rb', line 35

def next
  waiting.shift
end

#no_running?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/fasten/task_manager.rb', line 66

def no_running?
  running.empty?
end

#no_waiting?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/fasten/task_manager.rb', line 62

def no_waiting?
  waiting.empty?
end

#push(*items) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/fasten/task_manager.rb', line 18

def push(*items)
  items.each do |item|
    self << item
  end

  self
end

#running?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/fasten/task_manager.rb', line 74

def running?
  !running.empty?
end

#update(task) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fasten/task_manager.rb', line 39

def update(task)
  pending.delete task

  if task.state == :DONE
    done << task
    task.dependants.each { |dependant_task| dependant_task.depends.delete task }

    move_pending_to_waiting
  else
    failed << task
  end
end

#waitingObject



52
53
54
55
56
57
58
59
60
# File 'lib/fasten/task_manager.rb', line 52

def waiting
  return @waiting if @waiting

  reset
  setup_dependencies
  setup_targets
  setup_scores
  move_pending_to_waiting
end

#waiting?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/fasten/task_manager.rb', line 70

def waiting?
  !waiting.empty?
end