当前位置: 首页>>代码示例>>Python>>正文


Python DBSession.merge方法代码示例

本文整理汇总了Python中convirt.model.DBSession.merge方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.merge方法的具体用法?Python DBSession.merge怎么用?Python DBSession.merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在convirt.model.DBSession的用法示例。


在下文中一共展示了DBSession.merge方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: wait_for_workers_to_finish

# 需要导入模块: from convirt.model import DBSession [as 别名]
# 或者: from convirt.model.DBSession import merge [as 别名]
    def wait_for_workers_to_finish(self, task_ids):

        WRK_LOGGER.debug("wait_for_workers_to_finish for "+self.worker+" max_worker_wait_time: "+str(self.max_worker_wait_time))
        task_completed = False
        self.wait_start_time=datetime.utcnow()
        ###this is an infinite loop until we find a completed task
        ###we need to add some wait time to check on the status of child tasks
        while task_completed == False:
            time.sleep(5)
            completed_tasks = self.check_tasks_completed(task_ids)
            WRK_LOGGER.debug("wait_for_workers_to_finish for "+self.worker+" completed_tasks :"+str(completed_tasks))
            if len(completed_tasks) > 0:
                task_completed = True

                for task in completed_tasks:
                    self.worker_ids.remove(task['task_id'])
                    WRK_LOGGER.debug("child task completed, update EntityTasks "+self.worker+" completed_tasks :"+str(task['task_id']))
                    ets = DBSession.query(EntityTasks).\
                        filter(EntityTasks.worker_id==to_unicode(task['task_id'])).all()
                    for et in ets:
                        et.worker_id=None
                        et.finished=True
                        et.end_time=datetime.utcnow()
                        DBSession.merge(et)

                    transaction.commit()
                    WRK_LOGGER.debug("child tasks completed, updated EntityTasks "+self.worker)
            else :
#                if True:
#                    continue
                wait_time_sec=(datetime.utcnow()-self.wait_start_time).seconds
                WRK_LOGGER.debug("No completed child tasks for "+self.worker+". waiting for "+str(wait_time_sec))
                if wait_time_sec > self.max_worker_wait_time:
                    task_service = self.svc_central.get_service(self.task_service_id)
                    past_time = self.start_time-timedelta(minutes=1)

                    for task_id in task_ids:
                        task_obj = task_service.get_running_task_obj(task_id)
                        if task_obj:
                            (hung, completed, pending) = task_obj.get_running_status()
                            WRK_LOGGER.debug("HUNG STATUS for "+self.worker+":"+str(hung)+":"+str(task_id)+\
                                ":"+str(completed)+":"+str(pending))
                            if hung:
                                task_completed = True
                                self.worker_ids.remove(task_id)

                                WRK_LOGGER.debug("Hung task. Cleanup EntityTask for "+self.worker+". task id : "+str(task_id))
                                DBSession.query(EntityTasks).filter(EntityTasks.worker==self.worker).\
                                    filter(EntityTasks.entity_id.in_(completed)).\
                                    update(dict(worker_id=None,finished=True, end_time=datetime.utcnow()))
                                DBSession.query(EntityTasks).filter(EntityTasks.worker==self.worker).\
                                    filter(EntityTasks.entity_id.in_(pending)).\
                                    update(dict(worker_id=None,finished=True, start_time=past_time))

                                transaction.commit()
                                WRK_LOGGER.debug("Hung task. Cleaned up EntityTask for "+self.worker+". task id : "+str(task_id))
开发者ID:RDTeam,项目名称:openconvirt,代码行数:58,代码来源:WorkManager.py


注:本文中的convirt.model.DBSession.merge方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。