示例#1
0
文件: cqWorker.py 项目: pwwang/pwPHP
    def getRunnableJob(self):
        logging.debug('Try to get runnable job ...')
        job = trydb(self.dbfile, 'getJobs', "status='%s'" % cqStatus.PENDING, "ORDER BY priority, submitdate LIMIT 1")

        if len(job) > 0:
            logging.debug('Runnable job found: %s(%d)', job[0][1], job[0][0])
            return cmdJob(job[0][0], job[0][2], self.dbfile, lockFile)
        else:
            logging.debug('No runnable job found.')
            return False
示例#2
0
文件: cqWorker.py 项目: pwwang/pwPHP
 def update(self, vals):
     logging.debug('[JOB: %d] Try to update job: %s', self.jobid, json.dumps(vals))
     trydb(self.dbfile, 'updateJob', self.jobid, vals)
示例#3
0
文件: cqWorker.py 项目: pwwang/pwPHP
 def getPaused(self):
     pid = os.getpid()
     logging.debug('Try to get pause status ...')
     paused = trydb(self.dbfile, 'getPaused', pid)
     return int(paused)
示例#4
0
文件: cqWorker.py 项目: pwwang/pwPHP
            job.wait()
            if job.returncode == 0:
                logging.debug('[JOB: %d] Job finished normally, try to update the status and finishdate', self.jobid)
                self.update({'status': cqStatus.COMPLETE, 'finishdate': cqUtils.ts2ftime()})
            else:
                logging.debug('[JOB: %d] Job ended unexpectedly, try to update the status and finishdate', self.jobid)
                self.update({'status': cqStatus.KILLED, 'finishdate': cqUtils.ts2ftime()})
            #self.plugin.onJobEnd(self.jobid, self.cmd, job.returncode)
        except OSError, e:
            logging.debug('[JOB: %d] Job failed to start, try to update the status and finishdate', self.jobid)
            #self.plugin.onJobEnd(self.jobid, self.cmd, -99)
            self.update({'status': cqStatus.ERROR, 'finishdate': cqUtils.ts2ftime()})

        

if __name__ == '__main__' :
    pid      = os.getpid()
    dbfile   = sys.argv[1]
    interval = int(sys.argv[2])
    logfile  = sys.argv[3]
    loglevel = sys.argv[4]
    logging.basicConfig(filename=logfile, level=loglevel,format='[%(asctime)s][WORKER: '+ str(pid).ljust(5) +'][%(levelname)8s] %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
    logging.debug('Try to insert worker into database: %d' % pid)
    trydb(dbfile, 'insertWorker', pid)
    logging.info('Worker started at PID: %s', pid)
    
    lockFile = os.path.join(gettempdir(), 'cmdQueue-%s.lock' % md5.md5(dbfile).hexdigest())
    plugin = cqPlugin()
    plugin.onWorkerStart(pid)
    cmdWorker(dbfile, interval).start()