public
Fork of mojombo/god
Description: Ruby process monitor
Homepage: http://god.rubyforge.org
Clone URL: git://github.com/halorgium/god.git
Allow the status command to accept a task or group name.
halorgium (author)
Mon Mar 03 04:37:49 -0800 2008
commit  c6774ad939f90b3d7dff9eeb7048a79df4a457ec
tree    09e562524a3f7ae9b895e9453d1f37fe8959b805
parent  2445ce2657ace158c0eee8ac6bfc0705cfb78676
...
389
390
391
392
 
393
394
395
...
446
447
448
 
 
 
 
 
 
 
 
449
450
451
...
389
390
391
 
392
393
394
395
...
446
447
448
449
450
451
452
453
454
455
456
457
458
459
0
@@ -389,7 +389,7 @@ module God
0
   # Returns String[]:task_names
0
   def self.control(name, command)
0
     # get the list of items
0
- items = Array(self.watches[name] || self.groups[name]).dup
0
+ items = self.find_watches_for(name)
0
     
0
     jobs = []
0
     
0
@@ -446,6 +446,14 @@ module God
0
     exit!(0)
0
   end
0
   
0
+ # Find the watches for either the specified watch or group.
0
+ #
0
+ # Return all the watches if nil if provided
0
+ def self.find_watches_for(name)
0
+ return self.watches.values if name.nil?
0
+ Array(self.watches[name] || self.groups[name]).dup
0
+ end
0
+
0
   # Gather the status of each task.
0
   #
0
   # Examples
...
66
67
68
69
70
71
72
 
 
 
 
 
 
 
73
74
75
...
66
67
68
 
 
 
 
69
70
71
72
73
74
75
76
77
78
0
@@ -66,10 +66,13 @@ module God
0
       end
0
       
0
       def status_command
0
- watches = @server.status
0
- watches.keys.sort.each do |name|
0
- state = watches[name][:state]
0
- puts "#{name}: #{state}"
0
+ watches = @server.find_watches_for(@args[1])
0
+ unless watches.empty?
0
+ watches.sort_by {|w| w.name}.each do |watch|
0
+ puts "#{watch.name}: #{watch.state}"
0
+ end
0
+ else
0
+ puts 'No matching task or group'
0
         end
0
       end
0
       
...
370
371
372
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
373
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
374
375
376
...
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
0
@@ -370,7 +370,41 @@ class TestGod < Test::Unit::TestCase
0
     God.expects(:exit!)
0
     God.terminate
0
   end
0
+
0
+ # find_watches_for
0
+
0
+ def test_find_watches_for_nil_should_show_return_all_watches
0
+ God.watch { |w| w.name = 'foo'; w.start = 'bar' }
0
+
0
+ w = God.watches.values
0
+ set = God.find_watches_for(nil)
0
+ assert_equal(w, set)
0
+ end
0
+
0
+ def test_find_watches_for_a_watch_should_show_return_the_watch
0
+ God.watch { |w| w.name = 'foo'; w.start = 'bar' }
0
+
0
+ w = God.watches['foo']
0
+ set = God.find_watches_for('foo')
0
+ assert_equal([w], set)
0
+ end
0
   
0
+ def test_find_watches_for_a_group_should_show_return_the_members
0
+ God.watch { |w| w.name = 'foo_1'; w.group = 'bar'; w.start = 'baz' }
0
+ God.watch { |w| w.name = 'foo_2'; w.group = 'bar'; w.start = 'baz' }
0
+
0
+ w1, w2 = God.watches['foo_1'], God.watches['foo_2']
0
+ set = God.find_watches_for('bar')
0
+ assert_equal([w1, w2], set)
0
+ end
0
+
0
+ def test_status_should_show_unmonitored_for_nil_state
0
+ God.watch { |w| w.name = 'foo'; w.start = 'bar' }
0
+
0
+ w = God.watches['foo']
0
+ assert_equal({'foo' => {:state => :unmonitored}}, God.status)
0
+ end
0
+
0
   # status
0
   
0
   def test_status_should_show_state

Comments

    No one has commented yet.