Пример #1
0
    def doWork(cls, job):
        """
        __doWork__

        get the output of the job specified.
        return job when successful,
               None if the job does not need/allow further processing

        *** thread safe ***

        """

        try:

            ret = None
            logging.debug("%s: Getting output" % cls.fullId( job ) )

            # open database
            bossLiteSession = \
                           BossLiteAPI('MySQL', pool=cls.params['sessionPool'])

            # instantiate JobHandling object
            jHParams = deepcopy(cls.params['jobHandlingParams'])
            jHParams['bossLiteSession'] = bossLiteSession
            jobHandling = JobHandling( jHParams )

            # verify the status
            status = job.runningJob['processStatus']

            # a variable to check if the output already retrieved
            skipRetrieval = False

            # output retrieved before, then recover interrupted operation
            if status == 'output_retrieved':
                logging.warning("%s: Enqueuing previous ouput" % \
                                cls.fullId( job ) )
                skipRetrieval = True

            # non expected status, abandon processing for job
            elif status != 'in_progress' :
                logging.error("%s: Cannot get output, status is %s" % \
                              (cls.fullId( job ), status) )
                return

            # inconsistent status
            if status == 'in_progress' and job.runningJob['closed'] == 'Y':
                logging.warning(
                    "%s in status %s: Enqueuing previous output" % \
                    (cls.fullId( job ), status) )
                job.runningJob['processStatus'] = 'output_retrieved'
                bossLiteSession.updateDB( job )
                skipRetrieval = True

            logging.debug("%s: Processing output" % cls.fullId( job ) )

            if skipRetrieval :
                # job failed: perform postMortem operations and notify failure
                if job.runningJob['status'] in cls.failureCodes:
                    ret = jobHandling.performErrorProcessing(job)
                else:
                    ret = jobHandling.performOutputProcessing(job)

            else :
                ret = cls.action( bossLiteSession, job, jobHandling )

            logging.debug("%s : Processing output finished" % \
                          cls.fullId( job ) )

            # update status
            if ret is not None:
                job.runningJob['processStatus'] = 'processed'
                job.runningJob['closed'] = 'Y'
                # Fabio  # possible fix for SubSuccess bug
                job.runningJob['status'] = 'E'
                bossLiteSession.updateDB( job )
                ##

            else:
                # allow job to be reprocessed
                cls.recoverStatus( job, bossLiteSession )

                # if the job has not to be reprocessed
                if int( job.runningJob['getOutputRetry'] ) >= \
                       int( cls.params['maxGetOutputAttempts'] ) :

                    logging.error( "%s: LAST ATTEMPT RETRIEVAL FAILED!!!" % \
                                   cls.fullId( job ) )
                    
                    # set as failed
                    job.runningJob['status'] = 'A'
                    job.runningJob['processStatus'] = 'failed'
                    job.runningJob['statusScheduler'] = 'Abandoned'
                    job.runningJob['statusReason'] = \
                                           'GetOutput failed %s times' \
                                           % cls.params['maxGetOutputAttempts']

            # perform update
            bossLiteSession.updateDB( job )
            return ret

        # thread has failed because of a Bossite problem
        except BossLiteError, err:

            # allow job to be reprocessed
            cls.recoverStatus( job, bossLiteSession )

            # show error message
            logging.error( "%s failed to process output : %s" % \
                           ( cls.fullId( job ), str(err) ) )