避免重平衡

This commit is contained in:
wuaho 2021-10-26 16:50:28 +08:00
parent cd54024a42
commit e88c357d88
2 changed files with 4 additions and 2 deletions

2
app.py
View File

@ -27,7 +27,7 @@ def handler_userid(properties):
def run(): def run():
post_data = PostData() post_data = PostData(client)
schedule.every(60).seconds.do(post_data.post) schedule.every(60).seconds.do(post_data.post)
idx = get_data_id() idx = get_data_id()

View File

@ -14,8 +14,9 @@ requests.packages.urllib3.disable_warnings()
class PostData: class PostData:
def __init__(self): def __init__(self, kafka_client):
self.data_list = [] self.data_list = []
self.kafka_client = kafka_client
def add(self, data): def add(self, data):
self.data_list.append(data) self.data_list.append(data)
@ -53,6 +54,7 @@ class PostData:
except Exception as e: except Exception as e:
print(e) print(e)
finally: finally:
self.kafka_client.commit()
self.set_idx() self.set_idx()
self.clear_data() self.clear_data()