abundance 1.0.7 → 1.0.8
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.
- data/lib/garden.rb +35 -5
- data/lib/gardener.rb +17 -1
- metadata +1 -1
data/lib/garden.rb
CHANGED
@@ -31,15 +31,23 @@ class Garden
|
|
31
31
|
|
32
32
|
def initialize
|
33
33
|
@pid = fork do
|
34
|
-
@quit = false; @full_crop = false; @do_init = false
|
35
|
-
@harvest = []; @rows_port = []; @init_done = []
|
34
|
+
@quit = false; @full_crop = false; @do_init = false; @seed_all = nil
|
35
|
+
@harvest = []; @rows_port = []; @init_done = []; @seed_all_done = []; @seed_all_crop = []
|
36
36
|
@seeds = []; @sprouts = []; @crops = []; @id = 0
|
37
37
|
@socket_server = Toolshed.socket_server(Toolshed::garden_port)
|
38
38
|
@socket_client_temp = Toolshed.socket_client_temp
|
39
39
|
loop do
|
40
40
|
catch :fill_rows do
|
41
41
|
loop do
|
42
|
-
if ! @
|
42
|
+
if ! @seed_all.nil? && ! @rows_port.empty? && @seed_all_done.size != @seed_all[0]
|
43
|
+
row_port = @rows_port.shift
|
44
|
+
unless @seed_all_done.include?( row_port )
|
45
|
+
socket_client_temp(:seed_all,@seed_all[1],row_port)
|
46
|
+
@seed_all_done << row_port
|
47
|
+
else
|
48
|
+
@rows_port << row_port
|
49
|
+
end
|
50
|
+
elsif ! @seeds.empty? && ! @rows_port.empty?
|
43
51
|
seed = @seeds.shift
|
44
52
|
@sprouts[seed[:id]] = seed
|
45
53
|
row_port = @rows_port.shift
|
@@ -53,6 +61,8 @@ class Garden
|
|
53
61
|
unless @init_done.include?( row_port )
|
54
62
|
socket_client_temp(:init,seed,row_port)
|
55
63
|
@init_done << row_port; @do_init = nil
|
64
|
+
else
|
65
|
+
@rows_port << row_port
|
56
66
|
end
|
57
67
|
else
|
58
68
|
throw :fill_rows
|
@@ -133,11 +143,22 @@ class Garden
|
|
133
143
|
end
|
134
144
|
end
|
135
145
|
when :init
|
136
|
-
@do_init = true
|
146
|
+
@do_init = true
|
137
147
|
@init_return = {:clientaddr => clientaddr, :clientport => clientport}
|
138
148
|
when :init_crop
|
139
149
|
socket_server_send(command,true,clientaddr,clientport)
|
140
150
|
socket_server_send(command,data, @init_return[:clientaddr], @init_return[:clientport])
|
151
|
+
@init_return = Hash.new; @init_done = Array.new
|
152
|
+
when :seed_all
|
153
|
+
@seed_all = data
|
154
|
+
@seed_all_return = {:clientaddr => clientaddr, :clientport => clientport, :data => []}
|
155
|
+
when :seed_all_crop
|
156
|
+
socket_server_send(command,true,clientaddr,clientport)
|
157
|
+
@seed_all_crop << data
|
158
|
+
if @seed_all_crop.size == @seed_all[0]
|
159
|
+
socket_server_send(command,@seed_all_crop, @seed_all_return[:clientaddr], @seed_all_return[:clientport])
|
160
|
+
@seed_all = nil; @seed_all_return = Hash.new; @seed_all_done = Array.new; @seed_all_crop = Array.new
|
161
|
+
end
|
141
162
|
when :close
|
142
163
|
if data[:level] == :garden
|
143
164
|
@seeds_pid = data[:pid]
|
@@ -198,6 +219,7 @@ class Garden
|
|
198
219
|
row_port = Toolshed.available_port
|
199
220
|
@socket_client_perm = Toolshed.socket_client_perm
|
200
221
|
@pids << fork do
|
222
|
+
@seed_all = false
|
201
223
|
@socket_server = Toolshed.socket_server(row_port)
|
202
224
|
t1 = Thread.new do
|
203
225
|
gardener_block.call
|
@@ -218,13 +240,21 @@ class Garden
|
|
218
240
|
case command
|
219
241
|
when :sprout
|
220
242
|
$seed = data
|
243
|
+
when :seed_all
|
244
|
+
@seed_all = true
|
245
|
+
$seed = {:id => Process.pid, :seed => data}
|
221
246
|
when :init
|
222
247
|
command, data = socket_client_perm_duplex(:init_crop,$seed)
|
223
248
|
$seed = nil;
|
224
249
|
end
|
225
250
|
end
|
226
251
|
elsif $seed.include?(:success)
|
227
|
-
|
252
|
+
if @seed_all
|
253
|
+
command, data = socket_client_perm_duplex(:seed_all_crop,$seed)
|
254
|
+
@seed_all = false
|
255
|
+
else
|
256
|
+
command, data = socket_client_perm_duplex(:crop,$seed)
|
257
|
+
end
|
228
258
|
$seed = nil;
|
229
259
|
else
|
230
260
|
t1.run
|
data/lib/gardener.rb
CHANGED
@@ -58,13 +58,29 @@ class Gardener
|
|
58
58
|
# === Parameter
|
59
59
|
# * _command_ = a ruby expression or object
|
60
60
|
# === Example
|
61
|
-
# id_seed_1 = gardener.seed(system 'ruby -v')
|
61
|
+
# id_seed_1 = gardener.seed("system 'ruby -v'")
|
62
62
|
|
63
63
|
def seed(command)
|
64
64
|
command, data = socket_client_perm_duplex(:seed,command)
|
65
65
|
return data
|
66
66
|
end
|
67
67
|
|
68
|
+
# The +seed_all+ method allow to send a command to all row processes, usefull for a parameter change
|
69
|
+
# that needs to affect the prefered behaviour of all row. It returns an array containing hashes for each rows results.
|
70
|
+
# === Parameter
|
71
|
+
# * _command_ = a ruby expression or object
|
72
|
+
# === Example
|
73
|
+
# result = gardener.seed("pref local") # => [{:success=>true, :message=>["row pref changed to local"], :seed=>"pref local", :pid=>14915},
|
74
|
+
# {:success=>true, :message=>["row pref changed to local"], :seed=>"pref local", :pid=>14913}]
|
75
|
+
def seed_all(command)
|
76
|
+
seed = [@garden_rows.pids.size, command]
|
77
|
+
command, data = socket_client_perm_duplex(:seed_all, seed)
|
78
|
+
data.map! do |row|
|
79
|
+
{:success => row[:success], :message => row[:message], :pid => row[:id]}
|
80
|
+
end
|
81
|
+
return data
|
82
|
+
end
|
83
|
+
|
68
84
|
# The +growth+ method for the Gardener instance allow to get report of the growing process
|
69
85
|
# === Parameter
|
70
86
|
# The parameter given as a symbol specifies the level of growth report you wish to get:
|