IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 33294


Ignore:
Timestamp:
Feb 16, 2012, 3:35:10 PM (14 years ago)
Author:
rhenders
Message:

now updates clients table in ipptopsps Db with current timestamp while also checking if we should kill or pause this client; catching Ctrl-C for graceful exiting; log now sent to stout and file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippToPsps/jython/load.py

    r33271 r33294  
    55#
    66
     7import signal
    78import time
    89import sys
    910import os
    10 import socket
    1111import logging.config
    1212
     
    115115        batch.run()
    116116
     117        # check that we should continue
     118        checkClientStatus()
     119
    117120        ippToPspsDb.lockBatchTable()
    118121
     
    123126
    124127    ippToPspsDb.unlockTables()
     128
     129'''
     130Handler for Ctrl-C signal
     131'''
     132def signal_handler(signal, frame):
     133
     134    exitProgram("Ctrl-C")
     135
     136'''
     137Cleanly exits program, prints to log the way it exited
     138'''
     139def exitProgram(exiType):
     140
     141    logger.infoPair("Program exited", exiType)
     142    ippToPspsDb.removeClient(logger.host, logger.pid)
     143    sys.exit(0)
     144
     145
     146'''
     147Checks if we should pause or kill loading, otherwise updates the clients table with current time
     148'''
     149def checkClientStatus():
     150
     151    ippToPspsDb.updateClient(logger.host, logger.pid)
     152
     153    if ippToPspsDb.isKilled(logger.host, logger.pid): exitProgram("killed")
     154
     155    PAUSEPERIOD = 60
     156    while ippToPspsDb.isPaused(logger.host, logger.pid):
     157
     158        ippToPspsDb.updateClient(logger.host, logger.pid)
     159        if ippToPspsDb.isKilled(logger.host, logger.pid): exitProgram("killed while paused")
     160        logger.infoPair("Program paused for", "%d secs" % PAUSEPERIOD)
     161        time.sleep(PAUSEPERIOD)
     162
    125163
    126164'''
     
    139177# open config file
    140178config = Config(CONFIGPATH)
    141 #logger = config.getLogger(sys.argv[0], 0, 1)
    142 logger = config.getLogger(sys.argv[0])
     179logger = config.getLogger(sys.argv[0], 1, 1)
    143180
    144181# create various objects
     
    148185datastore = Datastore(logger, config, ippToPspsDb)
    149186
     187checkClientStatus()
     188
     189# catch Ctrl-C signal
     190signal.signal(signal.SIGINT, signal_handler)
     191
    150192# check we connected ok
    151193if not gpc1Db.everythingOK: sys.exit(1)
    152194if not ippToPspsDb.everythingOK: sys.exit(1)
    153195
    154 # get values from the configutaion file
    155196POLLPERIOD = 600
    156197
     
    178219   sys.exit(1)
    179220
     221
    180222'''
    181223Main processing loop:
     
    206248
    207249       while dec <= config.maxDec:
     250
     251           checkClientStatus()
    208252
    209253           # for each batch type
     
    228272
    229273               # do we pre-ingest stuff from DVO?
    230                if smfsPerGB > 0:
     274               if smfsPerGB > 40:
    231275                   if not dvo.sync():
    232276                       logger.errorPair("Could not sync DVO with MySQL", "skipping")
     
    238282               logger.infoBool("Using pre-ingested DVO data?", useFullTables)
    239283               processTheseItems(batchType, ids, useFullTables)
    240                
     284         
    241285               # in the test mode, we quit after submitting one batch
    242286               if config.test: break
     
    253297    time.sleep(POLLPERIOD)
    254298
    255 
     299exitProgram("end of program")
     300
Note: See TracChangeset for help on using the changeset viewer.