Class: Outback::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/outback/manager.rb

Constant Summary collapse

ROLLOUT =
1
ROLLBACK =
-1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeManager

Returns a new instance of Manager.



14
15
16
17
18
# File 'lib/outback/manager.rb', line 14

def initialize
  @tasks = []
  @names = {}
  @position = 0
end

Instance Attribute Details

#positionObject (readonly)

Returns the value of attribute position.



10
11
12
# File 'lib/outback/manager.rb', line 10

def position
  @position
end

#tasksObject (readonly)

Returns the value of attribute tasks.



10
11
12
# File 'lib/outback/manager.rb', line 10

def tasks
  @tasks
end

#watcher=(value) ⇒ Object (writeonly)

Sets the attribute watcher

Parameters:

  • value

    the value to set the attribute watcher to.



12
13
14
# File 'lib/outback/manager.rb', line 12

def watcher=(value)
  @watcher = value
end

#workdirObject

Returns the value of attribute workdir.



11
12
13
# File 'lib/outback/manager.rb', line 11

def workdir
  @workdir
end

Instance Method Details

#add_tasks(*tasks) ⇒ Object Also known as: add_task



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/outback/manager.rb', line 20

def add_tasks( *tasks )
  [*tasks].each do |task|
    task.workdir = @workdir unless task.workdir
    
    if task.name
      if @names.has_key?(task.name)
        raise DuplicateNamedTaskError, "Cannot add a named task more than once!"
      else
        @names[task.name] = @tasks.length
      end
    end
    
    @tasks << task
  end
end

#attempt(task) ⇒ Object



62
63
64
65
66
67
# File 'lib/outback/manager.rb', line 62

def attempt( task )
  method = {ROLLOUT => :rollout!, ROLLBACK => :rollback!}[@direction]
  ret = task.send(method)
  @watcher.notify(task) if @watcher
  return ret
end

#current_taskObject



69
70
71
# File 'lib/outback/manager.rb', line 69

def current_task
  @tasks[@position]
end

#find_task(name) ⇒ Object



38
39
40
# File 'lib/outback/manager.rb', line 38

def find_task( name )
  @tasks[@names[name]]
end

#rollback!Object



47
48
49
50
# File 'lib/outback/manager.rb', line 47

def rollback!
  @direction = ROLLBACK
  run
end

#rollback_from(task) ⇒ Object



57
58
59
60
# File 'lib/outback/manager.rb', line 57

def rollback_from( task )
  @position = @tasks.index(task) - 1
  rollback!
end

#rollout!Object



42
43
44
45
# File 'lib/outback/manager.rb', line 42

def rollout!
  @direction = ROLLOUT
  run
end

#rollout_from(task) ⇒ Object



52
53
54
55
# File 'lib/outback/manager.rb', line 52

def rollout_from( task )
  @position = @tasks.index(task)
  rollout!
end