同步表结构
This commit is contained in:
parent
26c57a624e
commit
f078d04279
@ -17,8 +17,8 @@ def create_consumer(partition=-1):
|
|||||||
# print(msg)
|
# print(msg)
|
||||||
topic = msg.topic
|
topic = msg.topic
|
||||||
val = msg.value
|
val = msg.value
|
||||||
if val.get('properties',{}).get('owner_name') not in ('gmhdgdt', 'gmhdtt'):
|
# if val.get('properties',{}).get('owner_name') not in ('gmhdgdt', 'gmhdtt'):
|
||||||
continue
|
# continue
|
||||||
yield topic, val
|
yield topic, val
|
||||||
|
|
||||||
return consumer
|
return consumer
|
||||||
|
@ -74,7 +74,7 @@ class Sketch:
|
|||||||
LIMIT 1 by `#account_id`"""
|
LIMIT 1 by `#account_id`"""
|
||||||
self.db_client.execute(sql)
|
self.db_client.execute(sql)
|
||||||
|
|
||||||
def alter_table(self, db, tb, data):
|
def alter_table(self, db, tb, data, try_cnt=10):
|
||||||
"""
|
"""
|
||||||
数据库字段检查
|
数据库字段检查
|
||||||
添加新字段为第一次出现类型
|
添加新字段为第一次出现类型
|
||||||
@ -114,8 +114,13 @@ class Sketch:
|
|||||||
try:
|
try:
|
||||||
self.db_client.execute(sql)
|
self.db_client.execute(sql)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f'添加字段 {k} 失败')
|
print(f'添加字段 {k} 失败,同步数据库表结构')
|
||||||
|
# 读取数据库表结构并设置
|
||||||
|
self.init_tb_struct()
|
||||||
default_field.pop(k)
|
default_field.pop(k)
|
||||||
|
if try_cnt < 0:
|
||||||
|
raise e
|
||||||
|
return self.alter_table(db, tb, data, try_cnt=try_cnt - 1)
|
||||||
|
|
||||||
if set(default_field) - keys:
|
if set(default_field) - keys:
|
||||||
self.up_tb_struct(db, tb, default_field)
|
self.up_tb_struct(db, tb, default_field)
|
||||||
|
Loading…
Reference in New Issue
Block a user