Class: Soda::Manager

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeManager

Returns a new instance of Manager.



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

def initialize
  @workers  = Set.new
  @fetcher  = Fetcher.new
  @mutex    = Mutex.new
  @shutdown = false

  count = Soda.options[:concurrency]
  count.times do
    @workers << Processor.new(self)
  end
end

Instance Attribute Details

#fetcherObject (readonly)

Returns the value of attribute fetcher.



3
4
5
# File 'lib/soda/manager.rb', line 3

def fetcher
  @fetcher
end

#mutexObject (readonly)

Returns the value of attribute mutex.



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

def mutex
  @mutex
end

#workersObject (readonly)

Returns the value of attribute workers.



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

def workers
  @workers
end

Instance Method Details

#on_died(worker) ⇒ Object

A processor will die on failed job execution. Replace it with a new one.



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/soda/manager.rb', line 29

def on_died(worker)
  mutex.synchronize do
    workers.delete(worker)

    unless shutdown?
      workers << (processor = Processor.new(self))

      processor.start
    end
  end
end

#shutdown!Object



45
46
47
# File 'lib/soda/manager.rb', line 45

def shutdown!
  @shutdown = true
end

#shutdown?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/soda/manager.rb', line 49

def shutdown?
  @shutdown
end

#startObject



17
18
19
# File 'lib/soda/manager.rb', line 17

def start
  workers.each(&:start)
end

#stopObject



21
22
23
24
25
26
# File 'lib/soda/manager.rb', line 21

def stop
  shutdown!

  workers.each(&:stop)
  workers.each(&:finish)
end