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


Python DBSession.close方法代码示例

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


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

示例1: dispatch

# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import close [as 别名]
    def dispatch(self):
        db_session = DBSession()

        self.handle_email_jobs(db_session)
        self.handle_create_tar_jobs(db_session)

        db_session.close()
开发者ID:anushreejangid,项目名称:csm,代码行数:9,代码来源:gjm.py

示例2: dispatch

# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import close [as 别名]
    def dispatch(self):
        db_session = DBSession()

        try:
            # Check if Scheduled Installs are allowed to run.
            if not db_session.query(SystemOption).first().can_install:
                return
                
            install_jobs = db_session.query(InstallJob).filter(
                InstallJob.scheduled_time <= datetime.datetime.utcnow()).order_by(InstallJob.scheduled_time.asc()).all()
            download_job_key_dict = get_download_job_key_dict()

            if len(install_jobs) > 0:
                for install_job in install_jobs:
                    if install_job.status != JobStatus.FAILED:
                        # If there is pending download, don't submit the install job
                        if self.is_pending_on_download(download_job_key_dict, install_job):
                            continue

                        # This install job has a dependency, check if the expected criteria is met
                        if install_job.dependency is not None:
                            dependency_completed = self.get_install_job_dependency_completed(db_session, install_job)
                            # If the dependency has not been completed, don't proceed
                            if len(dependency_completed) == 0:
                                continue

                        self.submit_job(InstallWorkUnit(install_job.host_id, install_job.id))

        except Exception:
            # print(traceback.format_exc())
            # Purpose ignore.  Otherwise, it may generate continue exception
            pass
        finally:
            db_session.close()
开发者ID:smjurcak,项目名称:csm,代码行数:36,代码来源:sum.py

示例3: run

# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import close [as 别名]
 def run(self):
     db_session = DBSession()   
     try:         
         system_option = SystemOption.get(db_session)            
         inventory_hour = system_option.inventory_hour
         db_session.close()
                     
         # Build a scheduler object that will look at absolute times
         scheduler = sched.scheduler(time.time, time.sleep)
         current_hour = datetime.datetime.now().hour
 
         # Put task for today at the designated hour.
         daily_time = datetime.time(inventory_hour)
         
         # If the scheduled time already passed, schedule it for tomorrow
         if current_hour > inventory_hour:
             first_time = datetime.datetime.combine(datetime.datetime.now() + datetime.timedelta(days=1), daily_time)
         else:
             first_time = datetime.datetime.combine(datetime.datetime.now(), daily_time)
         
         scheduler.enterabs(time.mktime(first_time.timetuple()), 1,
             self.scheduling, (scheduler, daily_time,))
        
         scheduler.run()
         
     except:
         logger.exception('InventoryManagerScheduler hit exception')
         db_session.close()
开发者ID:ommaurya,项目名称:csm,代码行数:30,代码来源:scheduler.py

示例4: scheduling

# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import close [as 别名]
    def scheduling(self, scheduler, daily_time):
        
        # First, re-set up the scheduler for the next day the same time. It is important to have
        # this logic on the top so that if any error encountered below, the scheduling still works.
        t = datetime.datetime.combine(datetime.datetime.now() + datetime.timedelta(days=1), daily_time)
        scheduler.enterabs(time.mktime(t.timetuple()), 1, self.scheduling, (scheduler, daily_time,))
            
        db_session = DBSession()
        
        try:
            system_option = SystemOption.get(db_session)
            
            # If software inventory is enabled, submit the inventory jobs
            if system_option.enable_inventory:
                inventory_jobs = db_session.query(InventoryJob).all()

                if len(inventory_jobs)> 0:
                    for inventory_job in inventory_jobs:
                        inventory_job.pending_submit = True
                    db_session.commit()
                        
            #Check if there is any housekeeping work to do
            self.perform_housekeeping_tasks(db_session, system_option)
            
        except:
            logger.exception('InventoryManagerScheduler hit exception')
        finally:
            db_session.close()
开发者ID:ommaurya,项目名称:csm,代码行数:30,代码来源:scheduler.py

示例5: process

# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import close [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

示例6: api_get_model_name_summary

# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import close [as 别名]
def api_get_model_name_summary(region_id):
    """
    Return the model name, in use (count), available (count) summary datatable json data
    """
    db_session = DBSession()

    rows = get_model_name_summary_query_results(db_session, region_id)

    db_session.close()
    return jsonify(**{'data': rows})
开发者ID:smjurcak,项目名称:csm,代码行数:12,代码来源:inventory.py

示例7: store_inventory

# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import close [as 别名]
    def store_inventory(self, ctx, inventory_data, chassis_indices):
        """
        Store/update the processed inventory data in database
        :param ctx: context object
        :param inventory_data: parsed inventory data as a list of dictionaries
        :param chassis_indices: a list of index/indices of chassis inventory dictionary in inventory_data
        :return: None
        """
        if len(chassis_indices) == 0 or len(chassis_indices) > len(inventory_data):
            logger = get_db_session_logger(ctx.db_session)
            logger.exception('index/indices of chassis found in inventory output is out of range for host ' +
                             '{}.'.format(ctx.host.hostname))
            return

        # Assign the ordering or "position" of inventory in output from show inventory
        # to each inventory entry, but adjust the ordering so that chassis always have
        # negative position(s) (so as to mark corresponding inventory as chassis)
        # and non-chassis always have consecutive non-negative positions in ascending order,
        # It goes like this - if there is only one chassis, its position will be -1,
        # the non-chassis inventories will have positions starting from 0
        # If there are multiple chassis, for example 3 chassis, chassis 0 will have position -3,
        # chassis 1 will have position -2, chassis 2 will have position -1, non-chassis will
        # still have positions starting from 0
        chassis_position = 0 - len(chassis_indices)
        for chassis_idx in chassis_indices:
            inventory_data[chassis_idx]['position'] = chassis_position
            chassis_position += 1

        idx = 0
        position = 0
        rack_number = 0
        while idx < len(inventory_data):
            if rack_number < len(chassis_indices):
                if idx == chassis_indices[rack_number]:
                    rack_number += 1
                else:
                    inventory_data[idx]['position'] = position
                    position += 1
            else:
                inventory_data[idx]['position'] = position
                position += 1
            idx += 1

        db_session = DBSession()
        # this is necessary for now because somewhere in the thread, can be
        # anywhere in the code, the db_session was not closed - to be found out later.
        db_session.close()

        if len(ctx.host.host_inventory) > 0:
            self.compare_and_update(ctx, db_session, inventory_data)
        else:
            self.store_new_inventory(db_session, inventory_data, ctx.host.id)

        db_session.close()
        return
开发者ID:smjurcak,项目名称:csm,代码行数:57,代码来源:base.py

示例8: dispatch

# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import close [as 别名]
    def dispatch(self):
        db_session = DBSession()
        try:
            inventory_jobs = db_session.query(InventoryJob).filter(InventoryJob.pending_submit == True).all()

            if len(inventory_jobs)> 0:
                for inventory_job in inventory_jobs:
                    self.submit_job(inventory_job.id)
        except:
            logger.exception('Unable to dispatch inventory job')  
        finally:
            db_session.close()
开发者ID:ommaurya,项目名称:csm,代码行数:14,代码来源:sim.py

示例9: process

# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import close [as 别名]
 def process(self):
     db_session = DBSession()
     ctx = None
     try:                                  
         install_job = db_session.query(InstallJob).filter(InstallJob.id == self.job_id).first()    
         if install_job is None:
             # This is normal because of race condition. It means the job is already deleted (completed).
             return
          
         if not can_install(db_session):
             # This will halt this host that has already been queued
             return
         
         host = db_session.query(Host).filter(Host.id == self.host_id).first()
         if host is None:
             logger.error('Unable to retrieve host %s', self.host_id)
             return
         
         handler_class = get_install_handler_class(host.platform)
         if handler_class is None:
             logger.error('Unable to get handler for %s, install job %s', host.platform, self.job_id)
     
         install_job.start_time = datetime.datetime.utcnow()
         install_job.set_status(JobStatus.PROCESSING)            
         install_job.session_log = create_log_directory(host.connection_param[0].host_or_ip, install_job.id)
         db_session.commit()
        
         ctx = InstallContext(host, db_session, install_job)
         ctx.operation_id = get_last_operation_id(db_session, install_job)
        
         handler = handler_class()
         handler.execute(ctx)
         
         if ctx.success:    
             # Update the software
             self.get_software(db_session, ctx)                
             archive_install_job(db_session, ctx, install_job, JobStatus.COMPLETED)                
         else:
             archive_install_job(db_session, ctx, install_job, JobStatus.FAILED)
             
         db_session.commit()
         
     except: 
         try:
             logger.exception('InstallManager hit exception - install job =  %s', self.job_id)
             archive_install_job(db_session, ctx, install_job, JobStatus.FAILED, trace=traceback.format_exc())
             db_session.commit()
         except:
             logger.exception('InstallManager hit exception - install job = %s', self.job_id)
     finally:
         # Must remove the host from the in progress list
         remove_host_from_in_progress(self.host_id)
         db_session.close()     
开发者ID:ommaurya,项目名称:csm,代码行数:55,代码来源:sum.py

示例10: dispatch

# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import close [as 别名]
    def dispatch(self):
        db_session = DBSession()
        try:
            inventory_jobs = db_session.query(InventoryJob).filter(InventoryJob.request_update == True).all()

            if len(inventory_jobs) > 0:
                for inventory_job in inventory_jobs:
                    self.submit_job(InventoryWorkUnit(inventory_job.host_id, inventory_job.id))

        except Exception:
            logger.exception('Unable to dispatch inventory job')  
        finally:
            db_session.close()
开发者ID:anushreejangid,项目名称:csm,代码行数:15,代码来源:sim.py

示例11: dispatch

# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import close [as 别名]
    def dispatch(self):
        db_session = DBSession()
 
        try:
            download_jobs = db_session.query(DownloadJob).all()
         
            for download_job in download_jobs:
                if download_job.status != JobStatus.FAILED:
                    self.submit_job(DownloadWorkUnit(download_job.id, download_job.cco_filename))

        except Exception:
            logger.exception('Unable to dispatch download job')  
        finally:
            db_session.close()
开发者ID:anushreejangid,项目名称:csm,代码行数:16,代码来源:sdm.py

示例12: api_get_chassis_summary

# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import close [as 别名]
def api_get_chassis_summary(region_id):
    """
    Return the chassis, count summary datatable json data
    """
    db_session = DBSession()

    chassis_summary_query = get_chassis_summary_query(db_session, region_id)

    rows = []
    for chassis_type, count in chassis_summary_query:
        rows.append({'chassis': chassis_type, 'count': count})

    db_session.close()
    return jsonify(**{'data': rows})
开发者ID:smjurcak,项目名称:csm,代码行数:16,代码来源:inventory.py

示例13: update_select2_options

# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import close [as 别名]
def update_select2_options(request_args, data_field):
    """
    This method helps populate the options used by ajax attached to Select2.
    The returned JSON contains the predefined tags.
    """
    db_session = DBSession()

    rows = []
    criteria = '%'
    if len(request_args) > 0:
        criteria += request_args.get('q') + '%'

    item_iter = db_session.query(data_field).filter(data_field.like(criteria)).distinct().order_by(data_field.asc())

    for item in item_iter:
        if item[0]:
            rows.append({'id': item[0], 'text': item[0]})
    db_session.close()
    return jsonify(**{'data': rows})
开发者ID:smjurcak,项目名称:csm,代码行数:21,代码来源:inventory.py

示例14: dispatch

# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import close [as 别名]
    def dispatch(self):
        db_session = DBSession()
 
        try:
            download_jobs = db_session.query(DownloadJob).all()
         
            for download_job in download_jobs:
                if download_job.status != JobStatus.FAILED:
                    with lock:
                        # If another download job for the same image name is already in progress,
                        # the download job will not be queued for processing
                        if download_job.cco_filename in in_progress_downloads:
                            continue

                    in_progress_downloads[download_job.cco_filename] = download_job.cco_filename
                    self.pool.submit(DownloadWorkUnit(download_job.id))
        except:
            logger.exception('Unable to dispatch download job')  
        finally:
            db_session.close()
开发者ID:ponnadarahul,项目名称:csm,代码行数:22,代码来源:sdm.py

示例15: api_get_inventory_with_duplicate_serial_number

# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import close [as 别名]
def api_get_inventory_with_duplicate_serial_number(region_id):
    """
    Return the serial number, count (# of inventory with that serial number)
    datatable json data
    """
    dt_params = DataTableParams(request)

    db_session = DBSession()

    clause = None
    if len(dt_params.search_value):
        criteria = '%' + dt_params.search_value + '%'
        clause = HostInventory.serial_number.like(criteria)

    serial_number_with_count_query = get_inventory_with_duplicate_serial_number_query(db_session, region_id)

    total_count = serial_number_with_count_query.count()
    if clause is not None:
        serial_number_with_count_query = serial_number_with_count_query.filter(clause)
        filtered_count = serial_number_with_count_query.count()
    else:
        filtered_count = total_count

    columns = [getattr(HostInventory.serial_number, dt_params.sort_order)()]

    serial_number_with_count = serial_number_with_count_query.order_by(columns[dt_params.column_order]) \
        .slice(dt_params.start_length, dt_params.start_length + dt_params.display_length).all()

    rows = []
    for serial_number, count in serial_number_with_count:
        rows.append({'serial_number': serial_number, 'count': count})

    db_session.close()

    response = dict()
    response['draw'] = dt_params.draw
    response['recordsTotal'] = total_count
    response['recordsFiltered'] = filtered_count
    response['data'] = rows

    return jsonify(**response)
开发者ID:smjurcak,项目名称:csm,代码行数:43,代码来源:datatable.py


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