Esempio n. 1
0
    def startLoop( self ) :  

        # reenqueue hanging tasks
        # TODO: reenqueuePendingTasks() 

        cnt = 0 
        taskIds = [] 
        self.terminate = False 

        while not self.terminate : 

            try: 

                # get a pending task from the queue 
                taskIds = dbLocker( dbLock , dequeueTask , SERVER_ID ) 

            except QueueEmpty : # no task to be processed 

                # perform DB cleanup 
                cleanup()

                # wait some ammount of time 
                time.sleep( QUEUE_EMPTY_QUERY_DELAY ) 

                # clear counter 
                cnt = 0 

                continue 

            # send task to worker 
            for taskId in list(taskIds) : 
                while not self.terminate : 
                    try : self.queue.put(taskId,True,QUEUE_PUT_TIMEOUT) 
                    except MPQFull : continue 
                    taskIds.remove(taskId) 
                    break 

            # increment counter 
            cnt += 1 

            # perform DB cleanup 
            if ( cnt > QUEUE_CLEAN_UP_COUNT ) : 
                cleanup()
                cnt = 0  

        info( "[MASTER]: termination in progress ... " ) 

        # try to reenequeue processes taken from the DB task queue 
        for item in taskIds : 
            debug( "[MASTER]: reenquing task ID=%i ... " % item ) 
            dbLocker( dbLock , reenqueueTask , item , message = "Reenqued by ATPD." ) 
        try: 
            while True : 
                item = self.queue.get(False)
                debug( "[MASTER]: reenquing task ID=%i ... " % item ) 
                dbLocker( dbLock , reenqueueTask , item , message = "Reenqued by ATPD." ) 
        except MPQEmpty : pass 
Esempio n. 2
0
def cleanup() : 
    """ cleanup function performing reenquing of zombie tasks """ 

    tasks = dbLocker( dbLock , reenqueueZombieTasks , "Reenqueued by ATPD after timeout." ) 

    for (id,task) in tasks : 
        warn( "[MASTER] Task %i:%s renqueued after timeout!"%(id,task) ) 

    tasks = dbLocker( dbLock , deleteRetiredTasks )  

    for (id,task) in tasks : 
        info( "[MASTER] Task %i:%s deleted after expiration!"%(id,task) ) 
Esempio n. 3
0
def cleanup():
    """ cleanup function performing reenquing of zombie tasks """

    tasks = dbLocker(dbLock, reenqueueZombieTasks,
                     "Reenqueued by ATPD after timeout.")

    for (id, task) in tasks:
        warn("[MASTER] Task %i:%s renqueued after timeout!" % (id, task))

    tasks = dbLocker(dbLock, deleteRetiredTasks)

    for (id, task) in tasks:
        info("[MASTER] Task %i:%s deleted after expiration!" % (id, task))
Esempio n. 4
0
def taskDispatch(taskID, threadID):
    """ 
        task dispatcher 

        based on the request class the right request hadler is used 
        to process the asynchronous requets 
    """
    # status logger
    pStatus = TaskStatus(taskID, dbLock)

    try:

        # get task parameters
        requestType, requestID, requestHandler, inputs = dbLocker(
            dbLock, startTask, taskID)

        info("[%3.3i] PROCESS: %s %s is running ... " %
             (threadID, requestType, requestID))

        # create importer object
        imp = Importer(requestHandler)

        # try to load the right module and handler
        imp.loadHandler()

        # execute handler - proper status logging is duty of the callback
        imp.handler(pStatus, inputs)

        # try to unload the handler
        imp.unloadHandler()

        # if no terminating status has been set do it right now
        dbLocker(dbLock, stopTaskSuccessIfNotFinished, taskID)

        info("[%3.3i] PROCESS: %s %s is finished ... " %
             (threadID, requestType, requestID))

    except (KeyboardInterrupt, SystemExit):
        raise
    except Exception as e:

        pStatus.setFailure(unicode(e))

        # finish the task
        error("[%3.3i] %s " % (threadID, unicode(e)))
Esempio n. 5
0
def taskDispatch( taskID , threadID ) : 
    """ 
        task dispatcher 

        based on the request class the right request hadler is used 
        to process the asynchronous requets 
    """ 
    # status logger 
    pStatus = TaskStatus( taskID , dbLock ) 

    try: 

        # get task parameters 
        requestType , requestID , requestHandler , inputs = dbLocker( dbLock , startTask , taskID ) 

        info( "[%3.3i] PROCESS: %s %s is running ... " % ( threadID , requestType , requestID ) ) 

        # create importer object 
        imp = Importer( requestHandler ) 

        # try to load the right module and handler 
        imp.loadHandler() 

        # execute handler - proper status logging is duty of the callback 
        imp.handler( pStatus , inputs ) 

        # try to unload the handler 
        imp.unloadHandler() 

        # if no terminating status has been set do it right now 
        dbLocker( dbLock , stopTaskSuccessIfNotFinished , taskID )

        info( "[%3.3i] PROCESS: %s %s is finished ... " % ( threadID , requestType , requestID ) ) 

    except (KeyboardInterrupt,SystemExit): raise 
    except Exception as e : 

        pStatus.setFailure( unicode(e) ) 

        # finish the task 
        error( "[%3.3i] %s " % ( threadID , unicode(e) ) ) 
Esempio n. 6
0
    def startLoop(self):

        # reenqueue hanging tasks
        # TODO: reenqueuePendingTasks()

        cnt = 0
        taskIds = []
        self.terminate = False

        while not self.terminate:

            try:

                # get a pending task from the queue
                taskIds = dbLocker(dbLock, dequeueTask, SERVER_ID)

            except QueueEmpty:  # no task to be processed

                # perform DB cleanup
                cleanup()

                # wait some ammount of time
                time.sleep(QUEUE_EMPTY_QUERY_DELAY)

                # clear counter
                cnt = 0

                continue

            # send task to worker
            for taskId in list(taskIds):
                while not self.terminate:
                    try:
                        self.queue.put(taskId, True, QUEUE_PUT_TIMEOUT)
                    except MPQFull:
                        continue
                    taskIds.remove(taskId)
                    break

            # increment counter
            cnt += 1

            # perform DB cleanup
            if (cnt > QUEUE_CLEAN_UP_COUNT):
                cleanup()
                cnt = 0

        info("[MASTER]: termination in progress ... ")

        # try to reenequeue processes taken from the DB task queue
        for item in taskIds:
            debug("[MASTER]: reenquing task ID=%i ... " % item)
            dbLocker(dbLock, reenqueueTask, item, message="Reenqued by ATPD.")
        try:
            while True:
                item = self.queue.get(False)
                debug("[MASTER]: reenquing task ID=%i ... " % item)
                dbLocker(dbLock,
                         reenqueueTask,
                         item,
                         message="Reenqued by ATPD.")
        except MPQEmpty:
            pass