ppool 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/ppool +14 -5
- data/lib/basic_process_controller.rb +43 -37
- data/lib/curses_process_controller.rb +99 -128
- data/lib/ppool.rb +4 -0
- data/lib/process_pool.rb +56 -53
- data/lib/shell_process_controller.rb +42 -40
- data/lib/terminal_process_controller.rb +59 -83
- data/lib/timed_process_controller.rb +94 -0
- metadata +44 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a26e4d31307303960169d895e99c920b2973274
|
4
|
+
data.tar.gz: ff136111314394c13522c6af72074f935d50cb4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 731c02140ced9acf4124d9322d3eeee11df2ae7a3b3d9b0cbd39b4760f09c2a1b9784e854a6cb795fb273484d394828fa50da9fdc656433a8a3eeff8647b6356
|
7
|
+
data.tar.gz: 22ef5674086659c33e6738b9c384b258e9fd29edd9632d9b078f79b52a6ff1c2c045de4f4b72980786d900afd6d9091c9ee0b6df5107ab846b1964648dc721d0
|
data/bin/ppool
CHANGED
@@ -27,13 +27,13 @@ require 'rubygems'
|
|
27
27
|
require 'ppool'
|
28
28
|
require 'optparse'
|
29
29
|
|
30
|
-
|
31
30
|
options = {
|
32
31
|
:size => 1,
|
33
32
|
:delay => 100,
|
34
33
|
:basic => false,
|
35
34
|
:logdir => "./ppool-logs",
|
36
|
-
:rmlogs => false
|
35
|
+
:rmlogs => false,
|
36
|
+
:timespec => nil
|
37
37
|
}
|
38
38
|
|
39
39
|
$USAGE = "Usage: ppool [options] COMMAND ARGS..."
|
@@ -44,6 +44,7 @@ OptionParser.new do |opts|
|
|
44
44
|
|
45
45
|
opts.on('-s', '--size SIZE', 'Initial pool size') { |v| options[:size] = v }
|
46
46
|
opts.on('-d', '--delay MSECS', 'The delay between checking the state of the process pool (default 100ms)') { |v| options[:delay] = v }
|
47
|
+
opts.on('-t', '--time TIME', 'Time limit') { |v| options[:timespec] = v }
|
47
48
|
opts.on('-b', '--basic', 'Basic (non curses) verion') { |v| options[:basic] = true}
|
48
49
|
opts.on('-r', '--rmlogs', 'Remove logs for processes that exited successfully') { |v| options[:rmlogs] = true}
|
49
50
|
opts.on('-l', '--logdir DIR', 'Log directory') { |v| options[:logdir] = v }
|
@@ -69,11 +70,19 @@ end
|
|
69
70
|
size = options[:size].to_i
|
70
71
|
delay = options[:delay].to_i
|
71
72
|
|
73
|
+
begin
|
74
|
+
time = options[:timespec] == nil ? nil : PPool.convert_time_to_secs(options[:timespec])
|
75
|
+
rescue ArgumentError => e
|
76
|
+
puts $USAGE
|
77
|
+
puts "error: #{e.message}"
|
78
|
+
exit(1)
|
79
|
+
end
|
80
|
+
|
72
81
|
if options[:basic]
|
73
|
-
controller = TerminalProcessController.new(size, delay, command, logdir, options[:rmlogs])
|
82
|
+
controller = PPool::TerminalProcessController.new(size, delay, command, time, logdir, options[:rmlogs])
|
74
83
|
else
|
75
|
-
controller = CursesProcessController.new(size, delay, command, logdir, options[:rmlogs])
|
84
|
+
controller = PPool::CursesProcessController.new(size, delay, command, time, logdir, options[:rmlogs])
|
76
85
|
end
|
77
86
|
|
78
|
-
ProcessPool.new(controller).run
|
87
|
+
PPool::ProcessPool.new(controller).run
|
79
88
|
|
@@ -22,54 +22,60 @@
|
|
22
22
|
# SOFTWARE.
|
23
23
|
#
|
24
24
|
|
25
|
-
|
25
|
+
module PPool
|
26
26
|
|
27
|
-
|
28
|
-
@time_started = Time.new.to_i
|
29
|
-
end
|
27
|
+
class BasicProcessController
|
30
28
|
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
def initialize
|
30
|
+
@time_started = Time.now.to_i
|
31
|
+
end
|
34
32
|
|
35
|
-
|
36
|
-
|
37
|
-
|
33
|
+
def running?
|
34
|
+
return true
|
35
|
+
end
|
38
36
|
|
39
|
-
|
40
|
-
|
41
|
-
|
37
|
+
def num_processes
|
38
|
+
return 1
|
39
|
+
end
|
42
40
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
41
|
+
def process_started(pid, num_processes)
|
42
|
+
puts "> process started #{pid}; num_processes #{num_processes}"
|
43
|
+
end
|
47
44
|
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
def run_process
|
46
|
+
info "#{Process.pid} running"
|
47
|
+
exit 0
|
48
|
+
end
|
51
49
|
|
52
|
-
|
53
|
-
|
54
|
-
|
50
|
+
def process_ended(pid, status)
|
51
|
+
puts "> process ended - pid #{pid}, status #{status}"
|
52
|
+
end
|
55
53
|
|
56
|
-
|
57
|
-
|
58
|
-
|
54
|
+
def progress(stats)
|
55
|
+
puts "> active #{stats[:active_processes]} started #{stats[:processes_started]} ended #{stats[:processes_ended]} errors #{stats[:errors]}"
|
56
|
+
end
|
59
57
|
|
60
|
-
|
61
|
-
|
62
|
-
|
58
|
+
def delay
|
59
|
+
return 0.1
|
60
|
+
end
|
63
61
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
mins = (secs / 60) % 60
|
68
|
-
secs = secs % 60
|
62
|
+
def info(m)
|
63
|
+
puts "+ #{m}"
|
64
|
+
end
|
69
65
|
|
70
|
-
|
71
|
-
|
66
|
+
def time_running
|
67
|
+
secs = time_running_secs
|
68
|
+
hours = (secs / (60 * 60)) % 24
|
69
|
+
mins = (secs / 60) % 60
|
70
|
+
secs = secs % 60
|
72
71
|
|
72
|
+
return "%.2d:%.2d:%.2d" % [hours, mins,secs]
|
73
|
+
end
|
73
74
|
|
74
|
-
|
75
|
+
def time_running_secs
|
76
|
+
Time.now.to_i - @time_started
|
77
|
+
end
|
75
78
|
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
@@ -24,154 +24,125 @@
|
|
24
24
|
|
25
25
|
require 'curses'
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
def initialize(size, delay, script, logdir, rmlogs)
|
30
|
-
super(script, logdir, rmlogs)
|
31
|
-
@finishing = false
|
32
|
-
@finished = false
|
33
|
-
@size = size
|
34
|
-
@delay = delay
|
35
|
-
@msg = ""
|
36
|
-
@last_stats = {}
|
37
|
-
init_window
|
38
|
-
end
|
39
|
-
|
40
|
-
def running?
|
41
|
-
return !@finished
|
42
|
-
end
|
43
|
-
|
44
|
-
def num_processes
|
45
|
-
return @size
|
46
|
-
end
|
27
|
+
module PPool
|
47
28
|
|
29
|
+
class CursesProcessController < TimedProcessController
|
48
30
|
|
49
|
-
|
50
|
-
|
51
|
-
|
31
|
+
def initialize(size, delay, script, time, logdir, rmlogs)
|
32
|
+
super(size, delay, script, time, logdir, rmlogs)
|
33
|
+
@msg = ""
|
34
|
+
@last_stats = {}
|
35
|
+
init_window
|
36
|
+
end
|
52
37
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
38
|
+
def progress(stats)
|
39
|
+
|
40
|
+
@last_stats = stats
|
41
|
+
|
42
|
+
draw_window
|
43
|
+
|
44
|
+
@win.attron(Curses.color_pair(3)|Curses::A_BOLD) {
|
45
|
+
@win.setpos(2 , 5)
|
46
|
+
@win.addstr("Time #{time_running}")
|
47
|
+
@win.setpos(3 , 5)
|
48
|
+
@win.addstr("Size #{@size}")
|
49
|
+
@win.setpos(4 , 5)
|
50
|
+
@win.addstr("Running #{stats[:active_processes]}")
|
51
|
+
@win.setpos(5 , 5)
|
52
|
+
@win.addstr("Started #{stats[:processes_started]}")
|
53
|
+
@win.setpos(6 , 5)
|
54
|
+
@win.addstr("Ended #{stats[:processes_ended]}")
|
55
|
+
@win.setpos(7 , 5)
|
56
|
+
@win.addstr("Errors #{stats[:errors]}")
|
57
|
+
@win.setpos(8 , 5)
|
58
|
+
@win.addstr("Logs #{@logdir}")
|
59
|
+
@win.setpos(9 , 5)
|
60
|
+
@win.addstr(" #{@msg}")
|
61
|
+
}
|
62
|
+
|
63
|
+
process_keys
|
64
|
+
|
65
|
+
if finishing?
|
66
|
+
if stats[:active_processes] == 0
|
67
|
+
finished
|
68
|
+
end
|
83
69
|
end
|
70
|
+
@win.refresh
|
71
|
+
|
84
72
|
end
|
85
|
-
@win.refresh
|
86
73
|
|
87
|
-
|
74
|
+
def init_window
|
88
75
|
|
89
|
-
|
90
|
-
return @delay / 1000
|
91
|
-
end
|
76
|
+
info "init_window"
|
92
77
|
|
78
|
+
Curses.init_screen
|
79
|
+
Curses.start_color
|
80
|
+
Curses.init_pair(1, Curses::COLOR_BLUE, Curses::COLOR_BLACK)
|
81
|
+
Curses.init_pair(2, Curses::COLOR_RED, Curses::COLOR_BLACK)
|
82
|
+
Curses.init_pair(3, Curses::COLOR_WHITE, Curses::COLOR_BLACK)
|
93
83
|
|
94
|
-
|
95
|
-
|
96
|
-
info "init_window"
|
84
|
+
lines = Curses.lines
|
85
|
+
cols = Curses.cols
|
97
86
|
|
98
|
-
|
99
|
-
|
100
|
-
Curses.init_pair(1, Curses::COLOR_BLUE, Curses::COLOR_BLACK)
|
101
|
-
Curses.init_pair(2, Curses::COLOR_RED, Curses::COLOR_BLACK)
|
102
|
-
Curses.init_pair(3, Curses::COLOR_WHITE, Curses::COLOR_BLACK)
|
87
|
+
height = 12
|
88
|
+
width = 70
|
103
89
|
|
104
|
-
|
105
|
-
#Curses.cbreak
|
106
|
-
#Curses.nonl
|
107
|
-
#Curses.curs_set(0)
|
90
|
+
@win = Curses::Window.new(height, width, 2, 2)
|
108
91
|
|
109
|
-
|
110
|
-
|
92
|
+
draw_window
|
93
|
+
end
|
111
94
|
|
112
|
-
|
113
|
-
|
95
|
+
def draw_window
|
96
|
+
@win.clear
|
97
|
+
@win.attron(Curses.color_pair(1)|Curses::A_NORMAL) {
|
98
|
+
@win.box('|', '-')
|
99
|
+
}
|
114
100
|
|
115
|
-
|
116
|
-
#@win.keypad = true
|
117
|
-
#@win.nodelay = true
|
101
|
+
end
|
118
102
|
|
119
|
-
|
103
|
+
def terminate
|
120
104
|
|
121
|
-
|
122
|
-
|
123
|
-
@win.attron(Curses.color_pair(1)|Curses::A_NORMAL) {
|
124
|
-
@win.box('|', '-')
|
125
|
-
}
|
126
|
-
|
127
|
-
end
|
105
|
+
info "terminate"
|
106
|
+
Curses.close_screen
|
128
107
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
puts ""
|
143
|
-
|
144
|
-
exit(0)
|
145
|
-
end
|
108
|
+
puts ""
|
109
|
+
puts "Time #{time_running}"
|
110
|
+
puts "Size #{@size}"
|
111
|
+
puts "Running #{@last_stats[:active_processes]}"
|
112
|
+
puts "Started #{@last_stats[:processes_started]}"
|
113
|
+
puts "Ended #{@last_stats[:processes_ended]}"
|
114
|
+
puts "Errors #{@last_stats[:errors]}"
|
115
|
+
puts "Logs #{@logdir}"
|
116
|
+
puts " #{@msg}"
|
117
|
+
puts ""
|
118
|
+
|
119
|
+
exit(0)
|
120
|
+
end
|
146
121
|
|
147
122
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
123
|
+
def process_keys
|
124
|
+
|
125
|
+
# Need to reset keyboard handling after a process
|
126
|
+
# has been forked.
|
127
|
+
Curses.noecho
|
128
|
+
Curses.cbreak
|
129
|
+
Curses.nonl
|
130
|
+
Curses.curs_set(0)
|
131
|
+
@win.keypad = true
|
132
|
+
@win.nodelay = true
|
133
|
+
|
134
|
+
case @win.getch
|
135
|
+
when '+', Curses::KEY_UP
|
136
|
+
inc_size
|
137
|
+
when '-', Curses::KEY_DOWN
|
138
|
+
dec_size
|
139
|
+
when 'q', 'Q'
|
140
|
+
finishing
|
141
|
+
when 'x', 'X'
|
142
|
+
terminate
|
166
143
|
end
|
167
|
-
|
168
|
-
@size = 0
|
169
|
-
@finishing = true
|
170
|
-
when 'x', 'X'
|
171
|
-
finished
|
172
|
-
end
|
173
|
-
end
|
144
|
+
end
|
174
145
|
|
146
|
+
end
|
175
147
|
|
176
148
|
end
|
177
|
-
|
data/lib/ppool.rb
CHANGED
@@ -22,8 +22,12 @@
|
|
22
22
|
# SOFTWARE.
|
23
23
|
#
|
24
24
|
|
25
|
+
|
26
|
+
require "process_pool_util.rb"
|
25
27
|
require "process_pool.rb"
|
26
28
|
require "basic_process_controller.rb"
|
27
29
|
require "shell_process_controller.rb"
|
30
|
+
require "timed_process_controller.rb"
|
28
31
|
require "terminal_process_controller.rb"
|
29
32
|
require "curses_process_controller.rb"
|
33
|
+
|
data/lib/process_pool.rb
CHANGED
@@ -22,79 +22,82 @@
|
|
22
22
|
# SOFTWARE.
|
23
23
|
#
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
def initialize(controller)
|
28
|
-
@controller = controller
|
29
|
-
@active_processes = 0
|
30
|
-
@started_count = 0
|
31
|
-
@ended_count = 0
|
32
|
-
@errors = 0
|
33
|
-
end
|
25
|
+
module PPool
|
34
26
|
|
27
|
+
class ProcessPool
|
35
28
|
|
36
|
-
|
29
|
+
def initialize(controller)
|
30
|
+
@controller = controller
|
31
|
+
@active_processes = 0
|
32
|
+
@started_count = 0
|
33
|
+
@ended_count = 0
|
34
|
+
@errors = 0
|
35
|
+
end
|
37
36
|
|
38
|
-
progress
|
39
37
|
|
40
|
-
|
38
|
+
def run
|
41
39
|
|
42
|
-
|
40
|
+
progress
|
43
41
|
|
44
|
-
|
45
|
-
while @active_processes < num_processes
|
42
|
+
while @controller.running?
|
46
43
|
|
47
|
-
|
44
|
+
num_processes = @controller.num_processes
|
48
45
|
|
49
|
-
|
50
|
-
|
51
|
-
end
|
46
|
+
# Create processes
|
47
|
+
while @active_processes < num_processes
|
52
48
|
|
49
|
+
@controller.info "num_proceses #{num_processes}, active_processes #{@active_processes}; forking"
|
53
50
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
51
|
+
pid = Process.fork do
|
52
|
+
@controller.run_process
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
@active_processes = @active_processes + 1
|
57
|
+
@controller.process_started(pid, @active_processes)
|
58
|
+
@started_count = @started_count + 1
|
60
59
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
60
|
+
progress
|
61
|
+
end
|
62
|
+
|
63
|
+
doneWaiting = false
|
64
|
+
while ! doneWaiting
|
65
|
+
begin
|
66
|
+
pidStatus = Process.wait2(-1, Process::WNOHANG)
|
67
|
+
if pidStatus != nil
|
68
|
+
@controller.process_ended(pidStatus[0], pidStatus[1].exitstatus)
|
69
|
+
@active_processes = @active_processes - 1
|
70
|
+
@ended_count = @ended_count + 1
|
71
|
+
if pidStatus[1].exitstatus != 0
|
72
|
+
@errors = @errors + 1
|
73
|
+
end
|
74
|
+
else
|
75
|
+
doneWaiting = true
|
76
|
+
end
|
77
|
+
rescue => e
|
73
78
|
doneWaiting = true
|
74
79
|
end
|
75
|
-
rescue => e
|
76
|
-
doneWaiting = true
|
77
|
-
#@controller.info "Exception #{e}"
|
78
80
|
end
|
79
|
-
end
|
80
81
|
|
81
|
-
|
82
|
+
progress
|
83
|
+
|
84
|
+
Kernel.sleep @controller.delay
|
82
85
|
|
83
|
-
|
86
|
+
end
|
87
|
+
@controller.terminate
|
84
88
|
|
85
89
|
end
|
86
|
-
@controller.finished
|
87
90
|
|
88
|
-
|
91
|
+
def progress
|
89
92
|
|
90
|
-
|
93
|
+
@controller.progress({
|
94
|
+
:active_processes => @active_processes,
|
95
|
+
:processes_started => @started_count,
|
96
|
+
:processes_ended => @ended_count,
|
97
|
+
:errors => @errors
|
98
|
+
})
|
99
|
+
end
|
91
100
|
|
92
|
-
@controller.progress({
|
93
|
-
:active_processes => @active_processes,
|
94
|
-
:processes_started => @started_count,
|
95
|
-
:processes_ended => @ended_count,
|
96
|
-
:errors => @errors
|
97
|
-
})
|
98
101
|
end
|
99
102
|
|
100
|
-
end
|
103
|
+
end
|
@@ -22,58 +22,60 @@
|
|
22
22
|
# SOFTWARE.
|
23
23
|
#
|
24
24
|
|
25
|
-
|
25
|
+
module PPool
|
26
26
|
|
27
|
-
|
28
|
-
super()
|
29
|
-
@script = script
|
30
|
-
@logdir = logdir
|
31
|
-
@rmlogs = rmlogs
|
32
|
-
@log = File.open("#{logdir}/ppool.log", 'w')
|
33
|
-
@stdout_log = {}
|
34
|
-
@stderr_log = {}
|
27
|
+
class ShellProcessController < BasicProcessController
|
35
28
|
|
36
|
-
|
29
|
+
def initialize(script, logdir, rmlogs)
|
30
|
+
super()
|
31
|
+
@script = script
|
32
|
+
@logdir = logdir
|
33
|
+
@rmlogs = rmlogs
|
34
|
+
@log = File.open("#{logdir}/ppool.log", 'w')
|
35
|
+
@stdout_log = {}
|
36
|
+
@stderr_log = {}
|
37
37
|
|
38
|
-
|
38
|
+
end
|
39
39
|
|
40
|
-
|
41
|
-
pid = Process.pid
|
42
|
-
|
43
|
-
stdout = "#{@logdir}/process_#{pid}_#{timestamp}.stdout"
|
44
|
-
stderr = "#{@logdir}/process_#{pid}_#{timestamp}.stderr"
|
45
|
-
stdin = "/dev/null"
|
40
|
+
def run_process
|
46
41
|
|
47
|
-
|
48
|
-
|
42
|
+
timestamp = Time.now.strftime('%Y%m%d%H%M%S')
|
43
|
+
pid = Process.pid
|
49
44
|
|
50
|
-
|
45
|
+
stdout = "#{@logdir}/process_#{pid}_#{timestamp}.stdout"
|
46
|
+
stderr = "#{@logdir}/process_#{pid}_#{timestamp}.stderr"
|
47
|
+
stdin = "/dev/null"
|
51
48
|
|
52
|
-
|
49
|
+
info "running #{@script} output to #{stdout}"
|
50
|
+
Kernel.exec("#{@script} > #{stdout} 2> #{stderr} < #{stdin}")
|
53
51
|
|
54
|
-
if @rmlogs && status == 0
|
55
|
-
delete_log_file(pid, 'stderr')
|
56
|
-
delete_log_file(pid, 'stdout')
|
57
52
|
end
|
58
|
-
|
59
|
-
end
|
60
53
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
54
|
+
def process_ended(pid, status)
|
55
|
+
if @rmlogs && status == 0
|
56
|
+
delete_log_file(pid, 'stdout')
|
57
|
+
delete_log_file(pid, 'stderr')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def info(m)
|
62
|
+
@log.write("#{m}\n")
|
63
|
+
@log.flush
|
64
|
+
end
|
65
65
|
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
67
|
+
def delete_log_file(pid, suffix)
|
68
|
+
begin
|
69
|
+
Dir.glob("#{@logdir}/process_#{pid}_*.#{suffix}") { |file|
|
70
|
+
info "deleting log file #{file} for process #{pid}"
|
71
|
+
File.delete(file)
|
72
|
+
}
|
73
|
+
rescue => e
|
74
|
+
info "error deleting log file for process #{pid}: #{e}"
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
76
78
|
|
77
79
|
end
|
78
80
|
|
79
|
-
end
|
81
|
+
end
|
@@ -25,112 +25,88 @@
|
|
25
25
|
require 'io/console'
|
26
26
|
require 'io/wait'
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
def initialize(size, delay, script, logdir, rmlogs)
|
31
|
-
super(script, logdir, rmlogs)
|
32
|
-
@finishing = false
|
33
|
-
@finished = false
|
34
|
-
@size = size
|
35
|
-
@delay = delay
|
36
|
-
@msg = ""
|
37
|
-
@last_stats = {}
|
38
|
-
@count = 0
|
39
|
-
|
40
|
-
Signal.trap('INT') do
|
41
|
-
finished
|
42
|
-
end
|
28
|
+
module PPool
|
43
29
|
|
44
|
-
|
30
|
+
class TerminalProcessController < TimedProcessController
|
45
31
|
|
46
|
-
|
47
|
-
|
48
|
-
|
32
|
+
def initialize(size, delay, script, time, logdir, rmlogs)
|
33
|
+
super(size, delay, script, time, logdir, rmlogs)
|
34
|
+
@msg = ""
|
35
|
+
@last_stats = {}
|
36
|
+
@count = 0
|
49
37
|
|
50
|
-
|
51
|
-
|
52
|
-
|
38
|
+
Signal.trap('INT') do
|
39
|
+
terminate
|
40
|
+
end
|
53
41
|
|
54
|
-
|
55
|
-
end
|
42
|
+
end
|
56
43
|
|
57
|
-
def progress(stats)
|
58
44
|
|
59
|
-
|
60
|
-
if @count % 20 == 0
|
45
|
+
def progress(stats)
|
61
46
|
|
62
|
-
|
63
|
-
|
64
|
-
puts "=============================================="
|
47
|
+
if stats != @last_stats
|
48
|
+
if @count % 20 == 0
|
65
49
|
|
50
|
+
puts "----------------------------------------------"
|
51
|
+
puts " Time | Size Active Started Ended Errors"
|
52
|
+
puts "=============================================="
|
53
|
+
|
54
|
+
end
|
55
|
+
puts(" %s | %4d %4d %4d %4d %4d\n" % [time_running, @size, stats[:active_processes], stats[:processes_started], stats[:processes_ended], stats[:errors]])
|
56
|
+
@last_stats = stats
|
57
|
+
@count = @count + 1
|
66
58
|
end
|
67
|
-
puts(" %s | %4d %4d %4d %4d %4d\n" % [time_running, @size, stats[:active_processes], stats[:processes_started], stats[:processes_ended], stats[:errors]])
|
68
|
-
@last_stats = stats
|
69
|
-
@count = @count + 1
|
70
|
-
end
|
71
59
|
|
72
|
-
|
60
|
+
process_keys
|
73
61
|
|
74
|
-
|
75
|
-
|
76
|
-
|
62
|
+
if finishing?
|
63
|
+
if stats[:active_processes] == 0
|
64
|
+
finished
|
65
|
+
end
|
77
66
|
end
|
78
67
|
end
|
79
68
|
|
69
|
+
def process_keys
|
70
|
+
|
71
|
+
case read_ch
|
72
|
+
when '+'
|
73
|
+
inc_size
|
74
|
+
@last_stats = {}
|
75
|
+
puts ""
|
76
|
+
when '-'
|
77
|
+
dec_size
|
78
|
+
@last_stats = {}
|
79
|
+
puts ""
|
80
|
+
when 'q', 'Q'
|
81
|
+
finishing
|
82
|
+
@last_stats = {}
|
83
|
+
puts ""
|
84
|
+
when 'x', 'X'
|
85
|
+
terminate
|
86
|
+
end
|
80
87
|
|
81
|
-
|
82
|
-
|
83
|
-
def delay
|
84
|
-
return @delay / 1000
|
85
|
-
end
|
86
|
-
|
88
|
+
end
|
87
89
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
if @size < 0
|
98
|
-
@size = 0
|
90
|
+
def read_ch
|
91
|
+
begin
|
92
|
+
system("stty raw")
|
93
|
+
if $stdin.ready?
|
94
|
+
c = $stdin.getc
|
95
|
+
return c.chr
|
96
|
+
end
|
97
|
+
ensure
|
98
|
+
system("stty -raw")
|
99
99
|
end
|
100
|
-
|
101
|
-
puts ""
|
102
|
-
when 'q', 'Q'
|
103
|
-
@size = 0
|
104
|
-
@finishing = true
|
105
|
-
@last_stats = {}
|
106
|
-
puts ""
|
107
|
-
when 'x', 'X'
|
108
|
-
finished
|
100
|
+
return nil
|
109
101
|
end
|
110
102
|
|
111
|
-
end
|
112
103
|
|
113
|
-
|
114
|
-
begin
|
115
|
-
system("stty raw")
|
116
|
-
if $stdin.ready?
|
117
|
-
c = $stdin.getc
|
118
|
-
return c.chr
|
119
|
-
end
|
120
|
-
ensure
|
104
|
+
def terminate
|
121
105
|
system("stty -raw")
|
106
|
+
puts ""
|
107
|
+
exit(0)
|
122
108
|
end
|
123
|
-
return nil
|
124
|
-
end
|
125
|
-
|
126
109
|
|
127
|
-
def finished
|
128
|
-
system("stty -raw")
|
129
|
-
puts ""
|
130
|
-
exit(0)
|
131
110
|
end
|
132
111
|
|
133
|
-
|
134
|
-
|
135
112
|
end
|
136
|
-
|
@@ -0,0 +1,94 @@
|
|
1
|
+
#
|
2
|
+
# MIT License
|
3
|
+
#
|
4
|
+
# Copyright (c) 2016 Paul Taylor
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be included in all
|
14
|
+
# copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
# SOFTWARE.
|
23
|
+
#
|
24
|
+
|
25
|
+
require 'io/console'
|
26
|
+
require 'io/wait'
|
27
|
+
|
28
|
+
module PPool
|
29
|
+
|
30
|
+
class TimedProcessController < ShellProcessController
|
31
|
+
|
32
|
+
def initialize(size, delay, script, time, logdir, rmlogs)
|
33
|
+
super(script, logdir, rmlogs)
|
34
|
+
|
35
|
+
@size = size
|
36
|
+
@time = time
|
37
|
+
@finishing = false
|
38
|
+
@finished = false
|
39
|
+
@size = size
|
40
|
+
@delay = delay
|
41
|
+
@msg = ""
|
42
|
+
|
43
|
+
Signal.trap('INT') do
|
44
|
+
finished
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
def running?
|
50
|
+
if @time != nil && time_running_secs > @time
|
51
|
+
@size = 0
|
52
|
+
@finishing = true
|
53
|
+
end
|
54
|
+
return !@finished
|
55
|
+
end
|
56
|
+
|
57
|
+
def num_processes
|
58
|
+
return @size
|
59
|
+
end
|
60
|
+
|
61
|
+
def process_started(pid, num_processes)
|
62
|
+
end
|
63
|
+
|
64
|
+
def delay
|
65
|
+
return @delay / 1000.0
|
66
|
+
end
|
67
|
+
|
68
|
+
def inc_size
|
69
|
+
@size = @size + 1
|
70
|
+
end
|
71
|
+
|
72
|
+
def dec_size
|
73
|
+
@size = @size - 1
|
74
|
+
if @size < 0
|
75
|
+
@size = 0
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def finishing
|
80
|
+
@size = 0
|
81
|
+
@finishing = true
|
82
|
+
end
|
83
|
+
|
84
|
+
def finishing?
|
85
|
+
return @finishing
|
86
|
+
end
|
87
|
+
|
88
|
+
def finished
|
89
|
+
@finished = true
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ppool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Taylor
|
@@ -24,6 +24,48 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.13'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.13'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
27
69
|
description: Start of pool of processes running a single command and control the pool
|
28
70
|
size via the keyboard.
|
29
71
|
email: pftylr@gmail.com
|
@@ -39,6 +81,7 @@ files:
|
|
39
81
|
- lib/process_pool.rb
|
40
82
|
- lib/shell_process_controller.rb
|
41
83
|
- lib/terminal_process_controller.rb
|
84
|
+
- lib/timed_process_controller.rb
|
42
85
|
homepage: http://rubygems.org/gems/ppool
|
43
86
|
licenses:
|
44
87
|
- MIT
|