def deleteTasks(self,tskList):
     db = DB()
     db.connect()
     response=[]
     for item in tskList:
         db.delTaskByID(item['imei'], item['hash'])
         response.append({'imei':item['imei'],'hash':item['hash'],'status':'deleted'})
     return response
 def dequeueTask(self, imei,hash):
     db=DB()
     db.connect()
     task=db.getTaskByID(imei, hash)
     if task!=None:
         if task.getStatus()==States.Running:
             return False
         db.delTaskByID(imei, hash)
         db.close()
         return True
     return False
 def enqueueTask(self,imei,hash,priority=Priorities.Low):
     db=DB()
     db.connect()
     task=Task(imei, hash, priority)
     status=db.addTask(task)
     db.close()
     if priority == Priorities.Critical:
         thread.start_new_thread(self.__realTimeJob,())
     return status
 def getTasks(self,tskList=None):
     db = DB()
     db.connect()
     response=[]
     tasks=db.getTasksWithID(tskList)
     for task in tasks:
         response.append({'imei':task.getIMEI(),'hash':task.getHash(),'code':task.getCode(),'status':str(task.getStatus()),'progress':task.getProgress()})
     db.close()
     #Return a tuple of all tasks and their parameters. To be used in a call to the DHServer
     return response
 def _loadQueue(self):
     self.pq=PriorityQueue(100)
     log.debug("Start loading queue")
     db=DB()
     db.connect()
     tasks=db.getAllTasks()
     for task in tasks:
         if task.getStatus() not in [States.Completed, States.Failed]:
             log.debug("Load task "+str(task))
             self.pq.put(task)
     db.close()
 def __dbUpdate(self,task):
     db = DB()
     db.connect()
     db.updateTask(task)
     db.close()