Skip to content

Commit

Permalink
Better way to define the management methods we support
Browse files Browse the repository at this point in the history
  • Loading branch information
dnaeon committed Jan 8, 2014
1 parent e8afb85 commit 8515306
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions src/vpoller/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class VPollerProxy(Daemon):
VPoller Proxy class
ZeroMQ proxy/broker which load-balances all client requests to a
pool of connected ZeroMQ workers.
pool of connected vPoller Workers workers.
Extends:
Daemon
Expand Down Expand Up @@ -196,16 +196,32 @@ def process_mgmt_message(self, msg):
"""
Processes a message for the management interface of the VPoller Proxy
An example message to get status information would be:
{
"method": "proxy.status"
}
An example message to shutdown the vPoller Proxy would be:
{
"method": "proxy.shutdown"
}
Args:
msg (dict): The client message to process
"""
# Check if we have a command to process
if not "cmd" in msg:
if not "method" in msg:
return "{ \"success\": -1, \"msg\": \"Missing command name\" }"

if msg["cmd"] == "shutdown":
self.time_to_die = True
logging.info("VPoller Proxy is shutting down")
return "{ \"success\": 0, \"msg\": \"Shutting down VPoller Proxy\" }"
elif msg["cmd"] == "status":
return "{ \"success\": 0, \"msg\": \"Okay, this is the status\" }"
else:
return "{ \"success\": 0, \"msg\": \"Unknown command %s received\" }" % msg["cmd"]
# Methods we support and process
methods = {
'proxy.status': self.get_proxy_status(msg),
'proxy.shutdown': self.proxy_shutdown(msg),
}

result = methods[msg['method']] if methods.get(msg['method']) else "{ \"status\": -1, \"msg\": \"Uknown command received\" }"

return result

0 comments on commit 8515306

Please sign in to comment.