當前位置: 首頁>>代碼示例>>Python>>正文


Python Custom_MySQL.rollback方法代碼示例

本文整理匯總了Python中custom.db.mysql.Custom_MySQL.rollback方法的典型用法代碼示例。如果您正苦於以下問題:Python Custom_MySQL.rollback方法的具體用法?Python Custom_MySQL.rollback怎麽用?Python Custom_MySQL.rollback使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在custom.db.mysql.Custom_MySQL的用法示例。


在下文中一共展示了Custom_MySQL.rollback方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run_task

# 需要導入模塊: from custom.db.mysql import Custom_MySQL [as 別名]
# 或者: from custom.db.mysql.Custom_MySQL import rollback [as 別名]
def run_task(self, task_param):



    mysql = Custom_MySQL(using='etl_manage')
    mysql.begin()

    try:

        '''
        業務代碼塊放下方
        '''
        dir_param ={'game':task_param['game'],
                    'platform':task_param['platform'],
                    'log_date':task_param['log_date'],
                    'log_name':task_param['log_name']}

        filename_dict = {'log_name':task_param['log_name'],'log_time':task_param['log_time']}
        
        '''
        遊戲\平台\日期\業務日誌名\日誌或者md5文件
        '''
        log_dir =  "/%(game)s/%(platform)s/%(log_date)s/%(log_name)s/" % dir_param

        lzo_file_name = "%(log_name)s_%(log_time)s.txt"% filename_dict

        local_log_dir = '/tmp'+log_dir


        dump_sql = task_param['dump_sql']
        dump_sql = dump_sql.replace('{table_name}',task_param['table_name'])
        dump_sql = dump_sql.replace('{partition_name}',task_param['partition_name'])
        dump_sql = dump_sql.replace('{db_name}',task_param['db_name'])
        print(dump_sql)

        result = mysql.dump(sql,local_log_dir+lzo_file_name)
        #print(result)



        '''
        將任務標識為加載文件完成:2
        '''
        datas = {'load_status':2}
        where = {}
        where['id'] = int(task_param['id'])

        mysql.update('etl_data_log',
                          ' id = %(id)d' % where,
                            **datas)
        mysql.commit()
        mysql.close()
        return True

    except Exception as exc:
        print (exc)
        mysql.rollback()
        raise self.retry(exc=exc, countdown=60)
開發者ID:jksd3344,項目名稱:Analoglogin,代碼行數:60,代碼來源:tasks.py

示例2: query_mysql

# 需要導入模塊: from custom.db.mysql import Custom_MySQL [as 別名]
# 或者: from custom.db.mysql.Custom_MySQL import rollback [as 別名]
def query_mysql(sql):

    mysql = Custom_MySQL(using='etl_manage')

    try:
        mysql.begin()
        result = mysql.query(sql)

        mysql.commit()
        mysql.close()

        return result

    except Exception as exc:
        #回滾
        mysql.rollback()
        print(exc)
        mysql.close()
開發者ID:jksd3344,項目名稱:Analoglogin,代碼行數:20,代碼來源:monitor_alarm.py

示例3: print

# 需要導入模塊: from custom.db.mysql import Custom_MySQL [as 別名]
# 或者: from custom.db.mysql.Custom_MySQL import rollback [as 別名]
        if file2dw_result['status'] != 0:
            print(now+" restart file2dw task error")

        file2dw_result_1 = mysql.update_by_sql('update file2dw_log set load_status=0,exec_num=0,in_queue=0 '
                                               'where load_status!=5 and in_queue=1 and log_time <="%s" and task_date="%s"'
                                               '' % (log_time_before_1hour, task_date))
        if file2dw_result_1['status'] != 0:
            print(now+" restart file2dw_1 task error")

    if '0500' < log_time < '1100':
        #重置dm2report_status
        dm2report_result = mysql.update_by_sql('update dm2report_log set status=0,exec_num=0,in_queue=0 '
                                               'where status=-1 and task_date="%s"' % task_date)
        if dm2report_result['status'] != 0:
            print(now+" restart dm2report task error")

        dm2report_result_1 = mysql.update_by_sql('update dm2report_log set status=0,exec_num=0,in_queue=0 '
                                                 'where status!=4 and in_queue=1 and log_time <="%s" and task_date="%s"'
                                                 '' % (log_time_before_1hour, task_date))
        if dm2report_result_1['status'] != 0:
            print(now+" restart dm2report_1 task error")

    mysql.commit()
    mysql.close()

except Exception as exc:
    #回滾
    mysql.rollback()
    print(exc)
    mysql.close()
開發者ID:jksd3344,項目名稱:Analoglogin,代碼行數:32,代碼來源:restart_task.py

示例4: CenterApp

# 需要導入模塊: from custom.db.mysql import Custom_MySQL [as 別名]
# 或者: from custom.db.mysql.Custom_MySQL import rollback [as 別名]

#.........這裏部分代碼省略.........
#                         where s.platform = '%s' and m.prefix = '%s'" % (param['platform'],param['game'])
#                 ip_list = self.exec_sql(s_sql)
#             
#             return ip_list
#         except Exception as exc:
#             print exc
#             #異常回滾
#             self.center_mysql.rollback()
    
    
    def get_log_ip(self):
        '''
            獲取所有log的IP
        '''
        
        ip_list = {}
        sql = "select t1.*,t2.prefix as platform  from \
                            (select m.prefix as gamename,a.public_ip as source_ip,a.platform_id from assets a inner join main_category m \
                            on a.main_category_id = m.id  \
                            where a.is_del = 0 and (a.hostname like '%%%%web_balance%%%%' or a.hostname like '%%%%web_admin%%%%') ) t1 \
                            left join platform t2 on t1.platform_id = t2.id \
                            where t1.source_ip is not null group by source_ip\
                union all \
                select t1.*,t2.prefix as platform from \
                            (select m.prefix as gamename,a.public_ip as source_ip,a.platform_id from assets a inner join main_category m \
                            on a.main_category_id = m.id  \
                            where a.is_del = 0 and a.hostname like '%%%%gameserver%%%%' ) t1 \
                            left join platform t2 on t1.platform_id = t2.id \
                            where t1.source_ip is not null group by source_ip"
        
        result = self.center_mysql.query(sql)
  
        for info in result:
            if info['gamename'] is None or info['platform'] is None:
                continue
            
            if info['gamename'].encode('utf8') not in ip_list:
                ip_list[info['gamename'].encode('utf8')] = {}
            
            if info['platform'].encode('utf8') not in ip_list[info['gamename'].encode('utf8')]:
                ip_list[info['gamename'].encode('utf8')][info['platform'].encode('utf8')] = []
                
            ip_list[info['gamename'].encode('utf8')][info['platform'].encode('utf8')].append(info['source_ip'].encode('utf8'))

        return ip_list
    
    
    def get_snap_ip(self):
        '''
            獲取所有快照的IP
        '''
        ip_list = {}
        s_sql = "select f.prefix as platform,s.prefix as source_ip,m.prefix as gamename from sub_category s inner join main_category m \
                        on s.main_category_id = m.id \
                left join platform f on f.id = s.platform_id"
        
        result = self.center_mysql.query(s_sql)
        
        for info in result:
            if info['gamename'] is None or info['platform'] is None:
                continue
            
            if info['gamename'].encode('utf8') not in ip_list:
                ip_list[info['gamename'].encode('utf8')] = {}
            
            if info['platform'].encode('utf8') not in ip_list[info['gamename'].encode('utf8')]:
                ip_list[info['gamename'].encode('utf8')][info['platform'].encode('utf8')] = []
                
            ip_list[info['gamename'].encode('utf8')][info['platform'].encode('utf8')].append(info['source_ip'].encode('utf8'))
        
#         print ip_list
        return ip_list
    
        
    def get_ip_list(self):
        '''
            整理IP列表
        '''
        try:
            ip_list = {}
          
            ip_list['basic'] = ['120.26.1.250']
                
            ip_list['mostsdk'] = ['120.26.13.150']

            ip_list['wanpay'] = ['112.124.116.44']
            
            log_list = self.get_log_ip();
             
            ip_list['log'] = log_list

            snap_list = self.get_snap_ip()
            ip_list['snap'] = snap_list
            
            return ip_list
        except Exception,e:
            print e
            print "異常"
            #異常回滾
            self.center_mysql.rollback()
開發者ID:jksd3344,項目名稱:Analoglogin,代碼行數:104,代碼來源:centerapp.py


注:本文中的custom.db.mysql.Custom_MySQL.rollback方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。