Skip to content

Commit

Permalink
added the listpids command
Browse files Browse the repository at this point in the history
  • Loading branch information
tarekziade committed May 2, 2012
1 parent fe94e85 commit a3ecc8e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions circus/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
incrproc,
list,
listen,
listpids,
numprocesses,
numwatchers,
options,
Expand Down
50 changes: 50 additions & 0 deletions circus/commands/listpids.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from circus.commands.base import Command
from circus.exc import ArgumentError


class ListPids(Command):
"""\
Get list of pids in a watcher
=============================
ZMQ Message
-----------
To get the list of pid in a watcher::
{
"command": "listpids",
"properties": {
"name": "nameofwatcher",
}
}
The response return the list asked.
Command line
------------
::
$ circusctl listpids <name>
"""
name = "listpids"

def message(self, *args, **opts):
if len(args) != 1:
raise ArgumentError("invalid number of arguments")

return self.make_message(name=args[0])

def execute(self, arbiter, props):
watcher = self._get_watcher(arbiter, props['name'])
pids = [process.pid for process in watcher.processes.values()]
pids.sort()
return {"pids": pids}

def console_msg(self, msg):
if 'pids' in msg:
return ",".join([str(pid) for pid in msg.get('pids')])
return self.console_error(msg)

0 comments on commit a3ecc8e

Please sign in to comment.