安装
python3.8.15
pip3.8 install pysnowflake==0.1.3
配置-settings.py
SNOWFLAKE_SERVER = dict(
host = "127.0.0.1",
port = 8910,
debug = False,
)
服务端-snowflake_service.py
import os
import sys
import settings
import signal
import subprocess
import shlex
def termination_signal_handler(signum, frame):
print ('catched terminate singal: %d' % signum)
globals_child.kill()
sys.exit()
if __name__ == "__main__":
signal.signal(signal.SIGTERM, termination_signal_handler)
signal.signal(signal.SIGINT, termination_signal_handler)
server_file_path = "snowflake_start_server"
if os.name == "posix":
server_file_path = "/usr/local/python38/bin/snowflake_start_server"
command = "{server_file_path} --address={host} --dc=0 --debug={debug} --port={port} --worker=0".format(
server_file_path = server_file_path,
host = settings.SNOWFLAKE_SERVER["host"],
debug = settings.SNOWFLAKE_SERVER["debug"],
port = settings.SNOWFLAKE_SERVER["port"],
)
print(command)
args = shlex.split(command)
global globals_child
globals_child = subprocess.Popen(args)
globals_child.wait()
客户端函数
import snowflake.client
def getSnowflakeId():
global globals_is_setup
if not globals_is_setup:
snowflake.client.setup(settings.SNOWFLAKE_SERVER["host"],settings.SNOWFLAKE_SERVER["port"])
globals_is_setup = True
return snowflake.client.get_guid()
supervisord部署
[program:snowflake_service]
directory=/data/xxx/xxx
command=python3 snowflake_service.py
autostart = true
startsecs = 5
user=sy
redirect_stderr = true
stdout_logfile_maxbytes = 20MB
stdout_logfile_backups = 20
stdout_logfile =/data/logs/xxx/snowflake_service.log