bj 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/HISTORY +18 -0
  2. data/TODO +4 -3
  3. data/lib/bj.rb +1 -0
  4. data/lib/bj/api.rb +1 -1
  5. data/lib/bj/runner.rb +73 -32
  6. 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
- - signals not operating properly on windows , non critical error tho...
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
@@ -30,6 +30,7 @@ unless defined? Bj
30
30
  require "rbconfig"
31
31
  require "set"
32
32
  require "erb"
33
+ require "drb"
33
34
  #
34
35
  # bootstrap rubygems
35
36
  #
@@ -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
@@ -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('SIGTERM', pid); rescue Exception; 42; end
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("signal"){ Signal.list.keys.index("HUP") ? "HUP" : "INT" }
53
- attribute("signaled"){ true }
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 = Bj.config[Runner.key]
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
- Process.kill Runner.signal, pid
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
- "#{ Bj.rails_env }.pid"
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.ruby } #{ Bj.script } run
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.signaled false
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
- trap(Runner.signal) do
232
- begin
233
- Runner.signaled!
234
- rescue Exception => e
235
- Bj.logger.error{ e }
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
- trap("INT"){ exit } unless Runner.signal == "INT"
240
- rescue Exception
241
- 42
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 options = {}
245
- Bj.transaction(options) do
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 options = {}
267
- Bj.transaction(options) do
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 options = {}
282
- Bj.transaction(options) do
283
- pid = Bj.config[Runner.key]
316
+ def register
317
+ Bj.transaction do
318
+ pid = Bj.config[key]
284
319
  return false if Util.alive?(pid)
285
- Bj.config[Runner.key] = Process.pid
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 options = {}
294
- Bj.transaction(options) do
295
- Bj.config.delete Runner.key
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
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: bj
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.4
7
- date: 2007-12-23 00:00:00 -07:00
6
+ version: 0.0.5
7
+ date: 2007-12-28 00:00:00 -07:00
8
8
  summary: bj
9
9
  require_paths:
10
10
  - lib