Class: RRRSpec::Server::Dispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/rrrspec/server/dispatcher.rb

Class Method Summary collapse

Class Method Details

.workObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rrrspec/server/dispatcher.rb', line 4

def self.work
  assigned = Hash.new { |hash,key| hash[key] = [] }
  unemployed = Hash.new { |hash,key| hash[key] = [] }
  Worker.list.each do |worker|
    unless worker.exist?
      worker.evict
    else
      taskset = worker.current_taskset
      if taskset
        assigned[taskset.key] << worker
      else
        unemployed[worker.worker_type] << worker
      end
    end
  end

  ActiveTaskset.list.each do |taskset|
    should_mark_running = false
    case taskset.status
    when 'succeeded', 'cancelled', 'failed'
      next
    when nil
      should_mark_running = true
    end

    # Cache the values
    max_workers = taskset.max_workers
    worker_type = taskset.worker_type
    while max_workers > assigned[taskset.key].size
      break if unemployed[worker_type].empty?
      worker = unemployed[worker_type].pop
      if should_mark_running
        taskset.update_status('running')
        should_mark_running = false
      end
      worker.enqueue_taskset(taskset)
      assigned[taskset.key] << worker
    end
  end
end

.work_loopObject



45
46
47
48
49
50
# File 'lib/rrrspec/server/dispatcher.rb', line 45

def self.work_loop
  loop do
    DispatcherQueue.wait
    work
  end
end