def __init__(self,type_queue,position=0): self.queue=MetaData(type=type_queue) if self.queue.find_one()==None: Logger.info('Queue of Type: {} does not exist in database, creating'.format(type_queue)) self.queue.create(type=type_queue,position=position).save()
class DBQueue_old: """ A queue in the database with the specified type(Just a unique identifier). This is used so that progress can be saved to database """ #self.type #self.queue def __init__(self,type_queue,position=0): self.queue=MetaData(type=type_queue) if self.queue.find_one()==None: Logger.info('Queue of Type: {} does not exist in database, creating'.format(type_queue)) self.queue.create(type=type_queue,position=position).save() def __get_queue(self): return self.queue.find_one() def increment(self,interval=1): queue=self.__get_queue() new_pos=queue.position+interval self.queue.update(position=new_pos) return new_pos def decrement(self,interval=1): pos=self.queue.find_one().position new_pos=pos-interval self.queue.update(position=new_pos) return new_pos def set(self,count=0): self.queue.update(position=count) def get(self): return self.queue.find_one().position