Class: Workpile::Service

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

Instance Method Summary collapse

Constructor Details

#initializeService

Returns a new instance of Service.



4
5
6
7
8
# File 'lib/workpile.rb', line 4

def initialize
  @queue = Queue.new
  @pids = []
  @boot_pids = []
end

Instance Method Details

#add_boot_client(pid) ⇒ Object



26
27
28
# File 'lib/workpile.rb', line 26

def add_boot_client(pid)
  @boot_pids << pid
end

#add_working_client(pid) ⇒ Object



18
19
20
# File 'lib/workpile.rb', line 18

def add_working_client(pid)
  @pids << pid
end

#kill_boot_childrenObject



41
42
43
44
45
46
# File 'lib/workpile.rb', line 41

def kill_boot_children
  return if @boot_pids.empty?
  s1 = @boot_pids.map{|pid| " /PID #{pid} " }
  IO.popen("start /b taskkill /F #{s1}")
  @boot_pids.clear
end

#kill_working_childrenObject



34
35
36
37
38
39
# File 'lib/workpile.rb', line 34

def kill_working_children
  return if @pids.empty?
  s1 = @pids.map{|pid| " /PID #{pid} " }
  IO.popen("start /b taskkill /F #{s1}")
  @pids.clear
end

#popObject



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

def pop
  @queue.pop
end

#push(obj) ⇒ Object



14
15
16
# File 'lib/workpile.rb', line 14

def push(obj)
  @queue.push obj
end

#remove_boot_client(pid) ⇒ Object



30
31
32
# File 'lib/workpile.rb', line 30

def remove_boot_client(pid)
  @boot_pids -= [pid]
end

#remove_working_client(pid) ⇒ Object



22
23
24
# File 'lib/workpile.rb', line 22

def remove_working_client(pid)
  @pids -= [pid]
end