From d66209de2998751963c177fec9ab3b91e075a5c6 Mon Sep 17 00:00:00 2001 From: Dan Bright Date: Fri, 3 Jun 2016 20:50:20 +0100 Subject: [PATCH 1/2] Add option to print task IDs to qinfo Option to print IDs (PIDs) of running clusters added to qinfo. This provides an easy way for scripts and process managers to fetch the PID(s) of running clusters. --- django_q/management/commands/qinfo.py | 11 +++++++++-- django_q/monitor.py | 11 +++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/django_q/management/commands/qinfo.py b/django_q/management/commands/qinfo.py index 84068fab..e82ee1d7 100644 --- a/django_q/management/commands/qinfo.py +++ b/django_q/management/commands/qinfo.py @@ -6,7 +6,7 @@ from django_q import VERSION from django_q.conf import Conf -from django_q.monitor import info +from django_q.monitor import info, get_ids class Command(BaseCommand): @@ -19,10 +19,17 @@ class Command(BaseCommand): dest='config', default=False, help='Print current configuration.'), + make_option('--ids', + action='store_true', + dest='ids', + default=False, + help='Print cluster task IDs (PIDs).'), ) def handle(self, *args, **options): - if options.get('config', False): + if options.get('ids', True): + get_ids() + elif options.get('config', False): hide = ['conf', 'IDLE', 'STOPPING', 'STARTING', 'WORKING', 'SIGNAL_NAMES', 'STOPPED'] settings = [a for a in dir(Conf) if not a.startswith('__') and a not in hide] self.stdout.write('VERSION: {}'.format('.'.join(str(v) for v in VERSION))) diff --git a/django_q/monitor.py b/django_q/monitor.py index 03582bff..001b53d1 100644 --- a/django_q/monitor.py +++ b/django_q/monitor.py @@ -187,3 +187,14 @@ def info(broker=None): term.white('{0:.4f}'.format(exec_time)) ) return True + + +def get_ids(): + # prints id (PID) of running clusters + stat = Stat.get_all() + if stat: + for s in stat: + print(s.cluster_id) + else: + print('No clusters appear to be running.') + return True From 515447d9998c2a590372d19c6f598fec35ce7781 Mon Sep 17 00:00:00 2001 From: Dan Bright Date: Thu, 9 Jun 2016 12:46:06 +0100 Subject: [PATCH 2/2] Replace optparse with argparse --- django_q/management/commands/qinfo.py | 30 +++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/django_q/management/commands/qinfo.py b/django_q/management/commands/qinfo.py index e82ee1d7..cdd82bfd 100644 --- a/django_q/management/commands/qinfo.py +++ b/django_q/management/commands/qinfo.py @@ -1,7 +1,4 @@ -from optparse import make_option - from django.core.management.base import BaseCommand - from django.utils.translation import ugettext as _ from django_q import VERSION @@ -13,18 +10,21 @@ class Command(BaseCommand): # Translators: help text for qinfo management command help = _('General information over all clusters.') - option_list = BaseCommand.option_list + ( - make_option('--config', - action='store_true', - dest='config', - default=False, - help='Print current configuration.'), - make_option('--ids', - action='store_true', - dest='ids', - default=False, - help='Print cluster task IDs (PIDs).'), - ) + def add_arguments(self, parser): + parser.add_argument( + '--config', + action='store_true', + dest='config', + default=False, + help='Print current configuration.', + ) + parser.add_argument( + '--ids', + action='store_true', + dest='ids', + default=False, + help='Print cluster task ID(s) (PIDs).', + ) def handle(self, *args, **options): if options.get('ids', True):