Changeset 466 for trunk/jobarchived


Ignore:
Timestamp:
02/21/08 10:16:36 (13 years ago)
Author:
bastiaans
Message:

jobarchived/jobarchived.py:

  • code cleanup
  • more comments
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/jobarchived/jobarchived.py

    r455 r466  
    2222#
    2323
    24 DEFAULT_SEARCH_PATH     = '/usr/share/jobarchived'
    25 
    26 import sys
    27 
    28 if DEFAULT_SEARCH_PATH not in sys.path:
    29 
    30         sys.path.append( DEFAULT_SEARCH_PATH )
    31 
    32 import getopt, syslog, ConfigParser
    33 
    34 def usage():
     24import getopt, syslog, ConfigParser, sys
     25
     26VERSION='0.3SVN'
     27
     28def usage( ver ):
     29
     30        print 'jobarchived %s' %VERSION
     31
     32        if ver:
     33                return 0
    3534
    3635        print
    37         print 'usage: jobarchived [options]'
    38         print 'options:'
    39         print '      --config, -c      configuration file'
    40         print '      --pidfile, -p     pid file'
    41         print '      --help, -h        help'
     36        print 'Purpose:'
     37        print '  The Job Archive Daemon (jobarchived) stores batch job information in a SQL database'
     38        print '  and node statistics in a RRD archive'
     39        print
     40        print 'Usage:   jobarchived [OPTIONS]'
     41        print
     42        print '  -c, --config=FILE      The configuration file to use (default: /etc/jobarchived.conf)'
     43        print '  -p, --pidfile=FILE     Use pid file to store the process id'
     44        print '  -h, --help             Print help and exit'
     45        print '  -v, --version          Print version and exit'
    4246        print
    4347
     
    4751        LONG_L  = [ 'help', 'config=', 'pidfile=' ]
    4852
    49         config_filename = None
     53        config_filename = '/etc/jobarchived.conf'
    5054
    5155        global PIDFILE
     
    7478                if opt in [ '--help', '-h' ]:
    7579
    76                         usage()
     80                        usage( false )
    7781                        sys.exit( 0 )
    7882
    79         if not config_filename:
    80 
    81                 config_filename = '/etc/jobarchived.conf'
     83                if opt in [ '--version', '-v' ]:
     84
     85                        usage( true )
     86                        sys.exit( 0 )
    8287
    8388        try:
     
    127132        cfg.read( filename )
    128133
    129         global DEBUG_LEVEL, USE_SYSLOG, SYSLOG_LEVEL, SYSLOG_FACILITY, GMETAD_CONF, ARCHIVE_XMLSOURCE, ARCHIVE_DATASOURCES, ARCHIVE_PATH, ARCHIVE_HOURS_PER_RRD, ARCHIVE_EXCLUDE_METRICS, JOB_SQL_DBASE, DAEMONIZE, RRDTOOL, JOB_TIMEOUT, MODRRDTOOL
     134        global DEBUG_LEVEL, USE_SYSLOG, SYSLOG_LEVEL, SYSLOG_FACILITY, GMETAD_CONF, ARCHIVE_XMLSOURCE
     135        global ARCHIVE_DATASOURCES, ARCHIVE_PATH, ARCHIVE_HOURS_PER_RRD, ARCHIVE_EXCLUDE_METRICS
     136        global JOB_SQL_DBASE, DAEMONIZE, RRDTOOL, JOB_TIMEOUT, MODRRDTOOL
    130137
    131138        ARCHIVE_PATH            = cfg.get( 'DEFAULT', 'ARCHIVE_PATH' )
     
    150157                MODRRDTOOL              = False
    151158
    152                 debug_msg( 0, "ERROR: py-rrdtool import FAILED: failing back to DEPRECATED use of rrdtool binary. This will slow down jobmond significantly!" )
     159                debug_msg( 0, "ERROR: py-rrdtool import FAILED: failing back to DEPRECATED use of rrdtool binary. This will slow down jobarchived significantly!" )
    153160
    154161                RRDTOOL                 = cfg.get( 'DEFAULT', 'RRDTOOL' )
     
    199206
    200207import xml.sax, xml.sax.handler, socket, string, os, os.path, time, thread, threading, random, re
    201 import rrdtool
    202208from pyPgSQL import PgSQL
    203209
     
    545551        def checkStaleJobs( self ):
    546552
     553                # Locate all jobs in the database that are not set to finished
     554                #
    547555                q = "SELECT * from jobs WHERE job_status != 'F'"
    548556
     
    566574                        job_start_timestamp     = row[8]
    567575
     576                        # If it was set to queued and we didn't see it started
     577                        # there's not point in keeping it around
     578                        #
    568579                        if job_status == 'Q' or not job_start_timestamp:
    569580
     
    574585                                start_timestamp = int( job_start_timestamp )
    575586
     587                                # If it was set to running longer than JOB_TIMEOUT
     588                                # close the job: it probably finished while we were not running
     589                                #
    576590                                if ( cur_time - start_timestamp ) > jobtimeout_sec:
    577591
     
    586600                debug_msg( 1, 'Found ' + str( len( cleanjobs ) ) + ' stale jobs in database: deleting entries' )
    587601
     602                # Purge these from database
     603                #
    588604                for j in cleanjobs:
    589605
     
    593609                debug_msg( 1, 'Found ' + str( len( timeoutjobs ) ) + ' timed out jobs in database: closing entries' )
    594610
     611                # Close these jobs in the database
     612                # update the stop_timestamp to: start_timestamp + requested wallclock
     613                # and set state: finished
     614                #
    595615                for j in timeoutjobs:
    596616
     
    642662                last_update = 0
    643663
     664                # Use the py-rrdtool module if it's available on this system
     665                #
    644666                if MODRRDTOOL:
    645667
     
    658680                                return 0
    659681
     682                # For backwards compatiblity: use the rrdtool binary if py-rrdtool is unavailable
     683                # DEPRECATED (slow!)
     684                #
    660685                else:
    661686                        debug_msg( 8, self.binary + ' info ' + filename )
     
    752777                """Setup initial XML connection and handlers"""
    753778
    754                 #self.myXMLGatherer     = XMLGatherer( ARCHIVE_XMLSOURCE.split( ':' )[0], ARCHIVE_XMLSOURCE.split( ':' )[1] )
    755                 #self.myXMLSource       = self.myXMLGatherer.getFileObject()
    756779                self.myXMLSource        = XMLSource
    757780                self.myXMLHandler       = TorqueXMLHandler( DataStore )
Note: See TracChangeset for help on using the changeset viewer.