Permalink
Browse files

gearman server info - implementd 'workers' output

  • Loading branch information...
1 parent 225b38c commit 3b813b2abecd2e71be27b9acb625cc792d0b6db1 @jsk jsk committed Apr 7, 2012
Showing with 19 additions and 4 deletions.
  1. +4 −2 README.rst
  2. +15 −2 django_gearman_commands/__init__.py
View
6 README.rst
@@ -38,11 +38,13 @@ BSD, see LICENSE for details
Authors and contributors
========================
-Jozef Ševčík, sevcik@codescale.net
+Author: Jozef Ševčík, sevcik@codescale.net
+
+Contributors:
+None. Be the first ! :)
TODO
====
* cleaning up gearman jobs after failed unit tests
* improve logging
-* gearman_server_info - output 'workers'
View
17 django_gearman_commands/__init__.py
@@ -99,6 +99,7 @@ def __init__(self, host):
self.host = host
self.server_version = None
self.tasks = None
+ self.workers = None
def get_server_info(self):
"""Read Gearman server info - status, workers and and version."""
@@ -109,6 +110,7 @@ def get_server_info(self):
self.server_version = client.get_version()
self.tasks = client.get_status()
+ self.workers = client.get_workers()
# use prettytable if available, otherwise raw output
try:
@@ -118,21 +120,32 @@ def get_server_info(self):
use_prettytable = False
if use_prettytable:
- # PrettyTable output
+ # use PrettyTable for output
+ # version
table = PrettyTable(['Gearman Server Host', 'Gearman Server Version'])
table.add_row([self.host, self.server_version])
result += '%s.\n\n' % str(table)
+ # tasks
table = PrettyTable(['Task Name', 'Total Workers', 'Running Jobs', 'Queued Jobs'])
for r in self.tasks:
table.add_row([r['task'], r['workers'], r['running'], r['queued']])
+
+ result += '%s.\n\n' % str(table)
+
+ # workers
+ table = PrettyTable(['Worker IP', 'Registered Tasks', 'Client ID', 'File Descriptor'])
+ for r in self.workers:
+ if r['tasks']: # ignore workers with no registered task
+ table.add_row([r['ip'], ','.join(r['tasks']), r['client_id'], r['file_descriptor']])
result += '%s.\n\n' % str(table)
else:
- # raw output
+ # raw output without PrettyTable
result += 'Gearman Server Host:%s\n' % self.host
result += 'Gearman Server Version:%s.\n' % self.server_version
result += 'Tasks:\n%s\n' % str(self.tasks)
+ result += 'Workers:\n%s\n' % str(self.workers)
return result

0 comments on commit 3b813b2

Please sign in to comment.