Example #1
0
    def __call__(self, event, payload):
        """
        Handles the event with payload.
        """
        
        # load queries for backend.
        myThread = threading.currentThread()
   
        # Now handle the message
        fields = {}
        if event in ['pilotShutdown']:
   
            self.logger.debug('PilotShutdownHandler:PilotShutdown:payload: %s' % payload)
            
            # Extract message attributes
            required = ['pilotId']
            for param in required:
                if not param in payload:
                    result = 'Error'
                    fields = {'Error': "pilotShutdown message requires \
'%s' field in payload" % param}
                    return {'msgType': result, 'payload': fields}
            pilotId = payload['pilotId']
            if 'reason' in payload:
                reason = payload['reason']
            else:
                reason = None

            finalRes = finishPilot(self, myThread.transaction, pilotId, reason)
              
            return finalRes
   
        else:
            # unexpected message, scream?
            pass
Example #2
0
    def algorithm(self, parameters):
        myThread = threading.currentThread()

        if parameters['hbValidity'] != None:
            hbValidity = parameters['hbValidity']
        else:
            hbValidity = heartbeatValidity

        res1 = res2 = []
        try:
            myThread.transaction.begin()

            # Retrieve pilots that have lived too long
            resTtl = self.queries.checkPilotsTtl()
            self.logger.debug("Too long-lived pilots: %s" % resTtl)

            # Retrieve pilots that have not reported for too long
            resHbt = self.queries.checkPilotsHeartbeat(hbValidity)
            self.logger.debug("Too careless pilots: %s" % resHbt)

            # Commit
            myThread.transaction.commit()

        except:
            ttype, val, tb = sys.exc_info()
            myThread.transaction.rollback()
            messg = 'Error in HeartbeatPollHandler: %s - %s '% (ttype, val)
            self.logger.warning(messg + "Trace: %s"% extract_tb(tb,limit=5))


        # TODO: Do nothing with pilots that lived too long?
        #       If they don't commit suicide or get killed, why not use them?
#        for pilot in resTtl:
#            finishPilot(self, myThread.transaction, \
#                                   pilot[0], 'TtlDeath')
                                   
        # Terminate those pilots that did not report (discard output)
        for pilot in resHbt:
            finishPilot(self, myThread.transaction, \
                                   pilot[0], 'HeartbeatDeath')

        return