本文整理汇总了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)
示例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()
示例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()
示例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()