35 lines
797 B
Python
35 lines
797 B
Python
import clickhouse_driver
|
|
from clickhouse_driver import Client
|
|
|
|
from ck.ck import CK
|
|
from common import *
|
|
|
|
from settings import settings
|
|
import traceback
|
|
|
|
ck_client = CK()
|
|
|
|
|
|
def run():
|
|
for topic, msg in consumer():
|
|
# print(msg)
|
|
try:
|
|
db = settings.APPID_TO_CKDB.get(msg['app_id'])
|
|
if 'user' in msg['type']:
|
|
table = 'user'
|
|
elif 'track' in msg['type']:
|
|
table = 'event'
|
|
else:
|
|
continue
|
|
del msg['type']
|
|
|
|
ck_client.send(db, table, msg)
|
|
except clickhouse_driver.errors.NetworkError:
|
|
ck_client.set_connect(Client(**settings.CK_CONFIG))
|
|
except Exception as e:
|
|
print(traceback.print_exc())
|
|
|
|
|
|
if __name__ == '__main__':
|
|
run()
|