def remove_by_taskid(self,task_id): if not task_id or not isinstance(str,task_id): return session = SafeSession() for task in session.query(TaskModel).filter_by(task_id=task_id).all(): session.delete(task) SafeSession.remove()
def get(self,task_id): try: session = SafeSession() r= session.query(TaskModel).filter_by(task_id=task_id).one() SafeSession.remove() except NoResultFound, e: r = None
def remove_by_project(self,project_name): if not project_name or not isinstance(str,project_name): return session = SafeSession() for task in session.query(TaskModel).filter_by(project_name=project).all(): session.delete(task) SafeSession.remove()
def page(self,index=1,page_count=10): session = SafeSession() if index<1:index=1 total_count = session.query(TaskModel).count() total_page = (total_count+page_count-1)/page_count if index>total_page:index = total_page r = session.query(TaskModel).order_by(TaskModel.end_time.desc()).offset( (index -1)*page_count).limit(page_count) SafeSession.remove() return r,index,total_page,page_count,total_count
def put(self,task): tm = TaskModel.from_task(task) if tm: session = SafeSession() session.add(tm) session.commit() SafeSession.remove() else: self.logger.error("init TaskModel object error %s",task.task_id )
def all(self): session = SafeSession() r = session.query(TaskModel).order_by(TaskModel.end_time.desc()) SafeSession.remove() return r
def count(self): session = SafeSession() r =session.query(TaskModel).count() SafeSession.remove() return r