Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

docs for ProcessSet

  • Loading branch information...
commit 2beb8336efb8e4da979c70375d162fa5667b4d42 1 parent 3ceb481
@adamwiggins authored
Showing with 19 additions and 2 deletions.
  1. +2 −2 lib/rush/box.rb
  2. +17 −0 lib/rush/process_set.rb
View
4 lib/rush/box.rb
@@ -41,8 +41,8 @@ def [](key)
filesystem[key]
end
- # Get the list of processes currently running on the box. Returns an array
- # of Rush::Process.
+ # Get the list of processes running on the box, not unlike "ps aux" in bash.
+ # Returns a Rush::ProcessSet.
def processes
Rush::ProcessSet.new(
connection.processes.map do |ps|
View
17 lib/rush/process_set.rb
@@ -1,3 +1,10 @@
+# A container for processes that behaves like an array, and adds process-specific operations
+# on the entire set, like kill.
+#
+# Example:
+#
+# processes.filter(:cmdline => /mongrel_rails/).kill
+#
class Rush::ProcessSet
attr_reader :processes
@@ -5,6 +12,13 @@ def initialize(processes)
@processes = processes
end
+ # Filter by any field that the process responds to. Specify an exact value,
+ # or a regular expression. All conditions are put together as a boolean
+ # AND, so these two statements are equivalent:
+ #
+ # processes.filter(:uid => 501).filter(:cmdline => /ruby/)
+ # processes.filter(:uid => 501, :cmdline => /ruby/)
+ #
def filter(conditions)
Rush::ProcessSet.new(
processes.select do |p|
@@ -17,10 +31,12 @@ def filter(conditions)
)
end
+ # Kill all processes in the set.
def kill
processes.each { |p| p.kill }
end
+ # Check status of all processes in the set, returns an array of booleans.
def alive?
processes.map { |p| p.alive? }
end
@@ -39,6 +55,7 @@ def ==(other)
end
end
+ # All other messages (like size or first) are passed through to the array.
def method_missing(meth, *args)
processes.send(meth, *args)
end
Please sign in to comment.
Something went wrong with that request. Please try again.