bj 0.0.4 → 0.0.5
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/HISTORY +18 -0
- data/TODO +4 -3
- data/lib/bj.rb +1 -0
- data/lib/bj/api.rb +1 -1
- data/lib/bj/runner.rb +73 -32
- metadata +2 -2
data/HISTORY
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
0.0.5:
|
2
|
+
- use full path to ruby for plugin mode
|
3
|
+
- plugin correctly installs bin -->> script
|
4
|
+
- plugin install uses --force
|
5
|
+
- properly quote paths in windows (spaces)
|
6
|
+
- swith win signal to ABRT (was INT)
|
7
|
+
- background job regrestration now uses ppid to pin the subprocess to a
|
8
|
+
parent
|
9
|
+
- use ppid to detect parent death and exit in event loop
|
10
|
+
- don't use gem dependanices in plugin as they are broken when loading from
|
11
|
+
muliple gem repos
|
12
|
+
- added a small amount of drb magic that allows signals to work across
|
13
|
+
processes even on windows (see http://drawohara.com/post/22540307)
|
14
|
+
|
15
|
+
0.0.4:
|
16
|
+
- basic functionality in widows
|
17
|
+
- several small bug fixes
|
18
|
+
|
1
19
|
0.0.3:
|
2
20
|
- *many* small bug fixes
|
3
21
|
|
data/TODO
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
|
2
|
-
|
2
|
+
? the whole gem_path thing is still fubar
|
3
|
+
|
4
|
+
? commands need quoting, esp for windows, "c:\Documents And..." etc
|
3
5
|
|
6
|
+
- signals not operating properly on windows , non critical error tho...
|
4
7
|
|
5
8
|
- need to figure out how to cache connections for Bj.in(...)
|
6
9
|
|
@@ -23,8 +26,6 @@
|
|
23
26
|
|
24
27
|
================================================================================
|
25
28
|
|
26
|
-
X the whole gem_path thing is still fubar
|
27
|
-
X commands need quoting, esp for windows, "c:\Documents And..." etc
|
28
29
|
X ./script/console submission hangs on windows
|
29
30
|
X default PATH setting
|
30
31
|
X install issues for dave? - gem_path...
|
data/lib/bj.rb
CHANGED
data/lib/bj/api.rb
CHANGED
@@ -153,7 +153,7 @@ class Bj
|
|
153
153
|
def plugin options = {}
|
154
154
|
options.to_options!
|
155
155
|
chroot do
|
156
|
-
util.spawn "./script/plugin install http://codeforpeople.rubyforge.org/svn/rails/plugins/bj", options
|
156
|
+
util.spawn "#{ Bj.ruby } ./script/plugin install http://codeforpeople.rubyforge.org/svn/rails/plugins/bj --force", options
|
157
157
|
end
|
158
158
|
end
|
159
159
|
end
|
data/lib/bj/runner.rb
CHANGED
@@ -19,6 +19,11 @@ class Bj
|
|
19
19
|
}.inspect
|
20
20
|
end
|
21
21
|
|
22
|
+
|
23
|
+
# TODO - this should try to use drb too
|
24
|
+
# TODO - pull out win stuff using platform.rb
|
25
|
+
# TODO - auto start runner?
|
26
|
+
|
22
27
|
def new_thread
|
23
28
|
this = self
|
24
29
|
Thread.new do
|
@@ -30,7 +35,7 @@ class Bj
|
|
30
35
|
this.pid = pid = pipe.pid
|
31
36
|
cleanup = lambda do
|
32
37
|
cleanup = lambda{}
|
33
|
-
begin; Process.kill(
|
38
|
+
begin; Process.kill(Runner.kill_signal, pid); rescue Exception; 42; end
|
34
39
|
end
|
35
40
|
at_exit &cleanup
|
36
41
|
Process.wait
|
@@ -49,8 +54,10 @@ class Bj
|
|
49
54
|
|
50
55
|
module ClassMethods
|
51
56
|
attribute("thread"){ Thread.current }
|
52
|
-
attribute("
|
53
|
-
attribute("
|
57
|
+
attribute("hup_signal"){ Signal.list.keys.index("HUP") ? "HUP" : "ABRT" }
|
58
|
+
attribute("hup_signaled"){ false }
|
59
|
+
attribute("kill_signal"){ "TERM" }
|
60
|
+
attribute("kill_signaled"){ false }
|
54
61
|
|
55
62
|
def tickle
|
56
63
|
return nil if Bj.config[Runner.no_tickle_key]
|
@@ -58,19 +65,27 @@ class Bj
|
|
58
65
|
end
|
59
66
|
|
60
67
|
def ping
|
61
|
-
pid =
|
68
|
+
pid = nil
|
69
|
+
uri = nil
|
70
|
+
process = nil
|
71
|
+
Bj.transaction do
|
72
|
+
pid = Bj.config[Runner.key(Process.pid)] || Bj.config[Runner.key]
|
73
|
+
uri = Bj.config["#{ pid }.uri"]
|
74
|
+
process = uri ? DRbObject.new(nil, uri) : Process
|
75
|
+
end
|
62
76
|
return nil unless pid
|
63
77
|
pid = Integer pid
|
64
78
|
begin
|
65
|
-
|
79
|
+
process.kill Runner.hup_signal, pid
|
66
80
|
pid
|
67
81
|
rescue Exception
|
68
82
|
false
|
69
83
|
end
|
70
84
|
end
|
71
85
|
|
72
|
-
def key
|
73
|
-
|
86
|
+
def key ppid = 0
|
87
|
+
ppid ||= 0
|
88
|
+
"#{ Bj.rails_env }.#{ ppid }.pid"
|
74
89
|
end
|
75
90
|
|
76
91
|
def no_tickle_key
|
@@ -92,14 +107,15 @@ class Bj
|
|
92
107
|
end
|
93
108
|
|
94
109
|
def command
|
95
|
-
%W[
|
96
|
-
#{ Bj.
|
110
|
+
"#{ Bj.ruby } " + %W[
|
111
|
+
#{ Bj.script }
|
112
|
+
run
|
97
113
|
--forever
|
98
114
|
--redirect=#{ log }
|
99
115
|
--ppid=#{ Process.pid }
|
100
116
|
--rails_env=#{ Bj.rails_env }
|
101
117
|
--rails_root=#{ Bj.rails_root }
|
102
|
-
].join(" ")
|
118
|
+
].map{|word| word.inspect}.join(" ")
|
103
119
|
end
|
104
120
|
|
105
121
|
def log
|
@@ -205,13 +221,15 @@ class Bj
|
|
205
221
|
end
|
206
222
|
end
|
207
223
|
|
208
|
-
Runner.
|
224
|
+
Runner.hup_signaled false
|
209
225
|
wait.times do
|
226
|
+
break if Runner.hup_signaled?
|
227
|
+
break if Runner.kill_signaled?
|
210
228
|
sleep 1
|
211
|
-
break if Runner.signaled?
|
212
229
|
end
|
213
230
|
|
214
231
|
break unless(limit or limit == false)
|
232
|
+
break if Runner.kill_signaled?
|
215
233
|
end
|
216
234
|
end
|
217
235
|
|
@@ -228,21 +246,38 @@ class Bj
|
|
228
246
|
end
|
229
247
|
|
230
248
|
def install_signal_handlers
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
249
|
+
Runner.hup_signaled false
|
250
|
+
hup_handler = nil
|
251
|
+
hup_handler =
|
252
|
+
trap Runner.hup_signal do |*a|
|
253
|
+
begin
|
254
|
+
Runner.hup_signaled true
|
255
|
+
rescue Exception => e
|
256
|
+
Bj.logger.error{ e } rescue nil
|
257
|
+
end
|
258
|
+
hup_handler.call *a rescue nil
|
236
259
|
end
|
237
|
-
end
|
238
260
|
|
239
|
-
|
240
|
-
|
241
|
-
|
261
|
+
Runner.kill_signaled false
|
262
|
+
kill_handler = nil
|
263
|
+
kill_handler =
|
264
|
+
trap Runner.kill_signal do |*a|
|
265
|
+
begin
|
266
|
+
Runner.kill_signaled true
|
267
|
+
rescue Exception => e
|
268
|
+
Bj.logger.error{ e } rescue nil
|
269
|
+
end
|
270
|
+
kill_handler.call *a rescue nil
|
271
|
+
end
|
272
|
+
|
273
|
+
begin
|
274
|
+
trap("INT"){ exit }
|
275
|
+
rescue Exception
|
276
|
+
end
|
242
277
|
end
|
243
278
|
|
244
|
-
def fill_morgue
|
245
|
-
Bj.transaction
|
279
|
+
def fill_morgue
|
280
|
+
Bj.transaction do
|
246
281
|
now = Time.now
|
247
282
|
jobs = Bj::Table::Job.find :all,
|
248
283
|
:conditions => ["state = 'running' and runner = ?", Bj.hostname]
|
@@ -263,8 +298,8 @@ class Bj
|
|
263
298
|
end
|
264
299
|
end
|
265
300
|
|
266
|
-
def archive_jobs
|
267
|
-
Bj.transaction
|
301
|
+
def archive_jobs
|
302
|
+
Bj.transaction do
|
268
303
|
now = Time.now
|
269
304
|
too_old = now - Bj.ttl
|
270
305
|
jobs = Bj::Table::Job.find :all,
|
@@ -278,11 +313,13 @@ class Bj
|
|
278
313
|
end
|
279
314
|
end
|
280
315
|
|
281
|
-
def register
|
282
|
-
Bj.transaction
|
283
|
-
pid = Bj.config[
|
316
|
+
def register
|
317
|
+
Bj.transaction do
|
318
|
+
pid = Bj.config[key]
|
284
319
|
return false if Util.alive?(pid)
|
285
|
-
Bj.config[
|
320
|
+
Bj.config[key] = Process.pid
|
321
|
+
DRb.start_service "druby://localhost:0", Process
|
322
|
+
Bj.config["#{ Process.pid }.uri"] = DRb.uri
|
286
323
|
end
|
287
324
|
at_exit{ unregister }
|
288
325
|
true
|
@@ -290,14 +327,18 @@ class Bj
|
|
290
327
|
false
|
291
328
|
end
|
292
329
|
|
293
|
-
def unregister
|
294
|
-
Bj.transaction
|
295
|
-
Bj.config.delete
|
330
|
+
def unregister
|
331
|
+
Bj.transaction do
|
332
|
+
Bj.config.delete key
|
296
333
|
end
|
297
334
|
true
|
298
335
|
rescue Exception
|
299
336
|
false
|
300
337
|
end
|
338
|
+
|
339
|
+
def key
|
340
|
+
@key ||= ( options[:ppid] ? Runner.key(options[:ppid]) : Runner.key )
|
341
|
+
end
|
301
342
|
end
|
302
343
|
send :include, Instance_Methods
|
303
344
|
end
|