【发布时间】:2021-04-07 07:42:15
【问题描述】:
我继承了一个需要重新修改的代码。频谱扫描错误不断发生,这是引发异常的地方:
try:
# iterate trough each record in json file
for i in sorted(tables_to_load, key=lambda x: (tables_to_load[x]["order"])):
# print(i)
# if table exclude flag is set to "N", proceed with load_table()
if tables_to_load[i]["exclude"] == "N":
try:
job_start_time = datetime.now()
logger.info("Begin load for: %s ---- %s ----" %(tables_to_load[i]["order"], i))
error_code = load_table(i, tables_to_load[i], from_date, to_date, max_proc, dm_updated,
process_flag)
job_end_time = datetime.now()
job_duration = (job_end_time - job_start_time).total_seconds()
logger.info("Load for table: %s -- time: %s seconds." %(i, job_duration))
except Exception as e:
#this is where the error is cought
logger.error("Load for table: %s FAILED: %s" %(i, e))
raise
#else the table is excluded and we skip it
else:
logger.info("Table excluded from load: %s " %i)
except Exception as e:
# upload error log to s3
s3.upload_file(filepath + filename, s3_logbucket, s3_logprefix + filename)
raise
基本上,该脚本会读取一个 json cfg 文件,其中包含一个由 YYYYMMDD 或 YYYYMMDDhhmmss 分区的外部表列表、RS 表和 RS 存储过程,它们将数据从 S3 加载到 RS。 当错误被捕获时,我不希望引发错误。或者更确切地说,我想在引发错误之前给它 3 次。我需要帮助编写那个迭代吗?
谢谢, 罗莎
【问题讨论】:
-
这能回答你的问题吗? Repeat Python function call on exception?
标签: python amazon-web-services amazon-s3 amazon-redshift