Commit b11a0c65 by 刘豪

添加重试

parent e0e96851
Showing with 31 additions and 16 deletions
...@@ -195,21 +195,7 @@ def get_supplier_id(supplier_name: str, conf: dict) -> int: ...@@ -195,21 +195,7 @@ def get_supplier_id(supplier_name: str, conf: dict) -> int:
return supplier_id return supplier_id
def down_and_handle(ftp_client):
if __name__ == '__main__':
environment = sys.argv[1]
if environment not in {"local", "dev", "prod"}:
sys.exit("param error!")
conf_environment = conf[environment]
ftp_client = ftp.FTPUtil(host=conf_environment["ftp"]["host"],
port=conf_environment["ftp"]["port"],
passive=True,
username=conf_environment["ftp"]["username"],
password=conf_environment["ftp"]["password"],
logger = logger)
if not os.path.exists(conf_environment["tmp_file_path"]):
os.makedirs(conf_environment["tmp_file_path"])
"""download the zip file""" """download the zip file"""
logger.info("下载压缩包") logger.info("下载压缩包")
ftp_client.download(remote_file_name_1, conf_environment["tmp_file_path"] + local_file_name_1) ftp_client.download(remote_file_name_1, conf_environment["tmp_file_path"] + local_file_name_1)
...@@ -236,16 +222,45 @@ if __name__ == '__main__': ...@@ -236,16 +222,45 @@ if __name__ == '__main__':
handle_hk_csv(extract_dir + handle_file_name_1, conf_environment, rs_hk_supplier_id) handle_hk_csv(extract_dir + handle_file_name_1, conf_environment, rs_hk_supplier_id)
handle_cn_csv(extract_dir + handle_file_name_3, conf_environment, rs_cn_supplier_id) handle_cn_csv(extract_dir + handle_file_name_3, conf_environment, rs_cn_supplier_id)
except Exception as e: except Exception as e:
logger.error("报错:{}".format(e)) logger.error("报错:{}, 重试".format(e))
down_and_handle(ftp_client)
return extract_dir
def remove_file(extract_dir):
"""remove the temp file, close the connection""" """remove the temp file, close the connection"""
logger.info("删除压缩包") logger.info("删除压缩包")
remove(extract_dir + handle_file_name_1) remove(extract_dir + handle_file_name_1)
remove(extract_dir + handle_file_name_3) remove(extract_dir + handle_file_name_3)
remove(conf_environment["tmp_file_path"] + local_file_name_1) remove(conf_environment["tmp_file_path"] + local_file_name_1)
remove(conf_environment["tmp_file_path"] + local_file_name_3) remove(conf_environment["tmp_file_path"] + local_file_name_3)
def run():
ftp_client = ftp.FTPUtil(host=conf_environment["ftp"]["host"],
port=conf_environment["ftp"]["port"],
passive=True,
username=conf_environment["ftp"]["username"],
password=conf_environment["ftp"]["password"],
logger = logger)
if not os.path.exists(conf_environment["tmp_file_path"]):
os.makedirs(conf_environment["tmp_file_path"])
extract_dir = down_and_handle(ftp_client)
remove_file(extract_dir)
logger.info("运行完成") logger.info("运行完成")
if __name__ == '__main__':
environment = sys.argv[1]
if environment not in {"local", "dev", "prod"}:
sys.exit("param error!")
conf_environment = conf[environment]
run()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment