argo_ls_jobs.py 1.2 KB
Newer Older
jtchilders's avatar
jtchilders committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from argo.UserJobReceiver import UserJobReceiver
from argo.models import ArgoJob
import os,sys,time,multiprocessing
import logging
logger = logging.getLogger('console')

class Command(BaseCommand):
   help = 'Lists jobs stored in the DB, '
   logger.debug('Listing jobs in the ARGO Service DB.')

   def add_arguments(self,parser):
      parser.add_argument('-pk', nargs='+', type=int, help="If given, only speficied pks will be reported.")

   def handle(self, *args, **options):
      process = {}
      
      jobs = []
      if options['pk'] is None:
         jobs = ArgoJob.objects.all()
      else:
         jobs = ArgoJob.objects.filter(pk__in=options['pk'])
      logger.info(str(len(jobs)) + ' jobs in the DB')
      if len(jobs) > 0:
        list = '\n\n'
        list += ArgoJob.get_header() + '\n'
        list += '---------------------------------------------------------------------------------------------------------------------------------------------------------------------\n'
        for job in jobs:
           list += job.get_line_string() + '\n'
        list += '\n\n'
        logger.info(list)