Beispiel #1
0
def taskerToComplete(ID):
    msg = "taskerToComplete"
    logger.info(msg)
    data = taskDB.getTaskInfo(ID)
    data.task_finish_time = datetime.datetime.now()
    taskDB.changeTaskInfo(data)
    changeTaskerStatus(ID, msg, parse.TASK_STATUS.complete)
Beispiel #2
0
def taskerLog(ID, log):
    data = taskDB.getTaskInfo(ID)
    if data.task_data is None:
        data.task_data = ""
    time_str = time()
    data.task_data += time_str + ":" + log + "\n"
    taskDB.changeTaskInfo(data)
Beispiel #3
0
def changeTaskerStatus(ID, message, status):
    data = taskDB.getTaskInfo(ID)
    if data.task_data is None:
        data.task_data = ""
    time_str = time()
    data.task_data += time_str + ":" + message + "\n"
    data.task_status = status
    taskDB.changeTaskInfo(data)
Beispiel #4
0
	def stopTask(self, data):
		task_ID = parse.paresID(data)
		if task_ID is None:
			return parse.responseError()
		task = taskDB.getTaskInfo(task_ID)
		if task.task_status != parse.TASK_STATUS.process:
			return parse.responseError()
		self.queue.put(data)
		logger.info("stopTask task_ID:" + str(task_ID))
		return parse.responseOK()
Beispiel #5
0
def testTasker(task_ID, para):
    task = taskDB.getTaskInfo(task_ID)
    task.task_status = parse.TASK_STATUS.startTasK
    task.data = "tasker start\n"
    taskDB.changeTaskInfo(task)
    import time
    time.sleep(1)
    taskerLog(task_ID, "process tasker")
    task.task_status = parse.TASK_STATUS.process
    task.save()
    for i in xrange(10):
        time.sleep(4)
        taskerLog(task_ID, str(i))
    taskerToComplete(task_ID)
    taskerLog(task_ID, "tasker over")
Beispiel #6
0
 def run(self):
     try:
         signal.signal(signal.SIGTERM, self.exit)
         task = taskDB.getTaskInfo(self.task_ID)
         self.task_para = task.task_para
         if task.task_type == TASK_TYPE.tfidf:
             import tfidfTasker
             tfidfTasker.startTasker(self.task_ID, task.task_para)
             # testTasker(self.task_ID, self.task_para)
     except SystemExit:
         logger.info("tasker exit with sys.exit()")
         exit(0)
     except:
         logger.error("tasker error exit:" + traceback.format_exc())
         taskerToError(self.task_ID, traceback.format_exc())
         sys.exit(-1)
Beispiel #7
0
 def handleTasker(self):
     # 每次处理进程列表中已经终止的那些
     # 前期先不管状态如何,后期可以根据退出的状态进行不同的操作
     # TODO
     self.lock.acquire()
     for t in self.taskerList.keys():
         if not self.taskerList[t].is_alive():
             # 看任务是否完成,没有完成则标记为error
             task = taskDB.getTaskInfo(t)
             if task.task_status == parse.TASK_STATUS.process or\
              task.task_status == parse.TASK_STATUS.startTask:
                 task.task_status = parse.TASK_STATUS.error
                 task.save()
                 logger.info("get a stoped task turn to error")
             self.taskerList[t].join()
             del self.taskerList[t]
     self.lock.release()