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


Python DBSession.expunge方法代码示例

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


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

示例1: process

# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import expunge [as 别名]
    def process(self):
        
        db_session = DBSession()
        host_id = None
        inventory_job = None
        ctx = None
        try:
            
            inventory_job = db_session.query(InventoryJob).filter(InventoryJob.id == self.job_id).first()    
            if inventory_job is None:
                logger.error('Unable to retrieve inventory job: %s' % self.job_id)
                return
            
            host_id = inventory_job.host_id
            host = db_session.query(Host).filter(Host.id == host_id).first()
            if host is None:
                logger.error('Unable to retrieve host: %s' % host_id)
            
            handler_class = get_inventory_handler_class(host.platform)
            if handler_class is None:
                logger.error('Unable to get handler for %s, inventory job %s', host.platform, self.job_id)
            
            inventory_job.set_status(JobStatus.PROCESSING)
            inventory_job.session_log = create_log_directory(host.connection_param[0].host_or_ip, inventory_job.id)
            db_session.commit()         
            
            # Delegates the get_software logic to the handler
            ctx = InventoryContext(host, db_session, inventory_job)

            handler = handler_class()
            handler.execute(ctx)
            
            if ctx.success:
                archive_inventory_job(db_session, inventory_job, JobStatus.COMPLETED)
            else:
                # removes the host object as host.packages may have been modified.
                db_session.expunge(host)
                archive_inventory_job(db_session, inventory_job, JobStatus.FAILED)
            
            # Reset the pending retrieval flag
            inventory_job.pending_submit = False
            db_session.commit()

        except:
            try:
                logger.exception('InventoryManager hit exception - inventory job = %s', self.job_id)
                archive_inventory_job(db_session, inventory_job, JobStatus.FAILED, trace=sys.exc_info)
                # Reset the pending retrieval flag
                inventory_job.pending_submit = False
                db_session.commit()
            except:
                logger.exception('InventoryManager hit exception - inventory job = %s', self.job_id)
        finally:
            with lock:
                if self.job_id is not None and self.job_id in in_progress_jobs: del in_progress_jobs[self.job_id]
            db_session.close()       
开发者ID:ommaurya,项目名称:csm,代码行数:58,代码来源:sim.py


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