fix:return文をTryExceptに追加した
This commit is contained in:
parent
0b98a89448
commit
1f5d0c1abe
@ -1,5 +1,7 @@
|
||||
from datetime import datetime
|
||||
|
||||
# 定数
|
||||
LOG_LEVEL = {"d": 'Debug'}
|
||||
MODE_TYPE = {
|
||||
'n': 'normal',
|
||||
'd': 'debug',
|
||||
@ -8,4 +10,4 @@ MODE_TYPE = {
|
||||
|
||||
def debug_log(log, log_info, mode):
|
||||
if MODE_TYPE['d'] == mode:
|
||||
print(f'{str(datetime.now())} {log_info} Debug {log}')
|
||||
print(f'{str(datetime.now())} {log_info} {LOG_LEVEL["d"]} {log}')
|
||||
|
||||
@ -151,8 +151,8 @@ def init(bucket_name, target_key, target_data_source, target_file_name, log_info
|
||||
try:
|
||||
# ⑨ 初期処理終了ログを出力する
|
||||
print(f'{str(datetime.now())} {log_info} {LOG_LEVEL["i"]} I-INI-21 - 初期処理を終了します')
|
||||
|
||||
return settings_key
|
||||
except Exception as e:
|
||||
print(f'{str(datetime.now())} {log_info} {LOG_LEVEL["e"]} E-INI-99 - エラー内容:{e}')
|
||||
error(bucket_name, target_data_source, target_file_name, log_info)
|
||||
|
||||
return settings_key
|
||||
|
||||
@ -88,23 +88,13 @@ def main(bucket_name, target_key, target_data_source, target_file_name, settings
|
||||
sql_truncate = f'TRUNCATE table {settings_list[SETTINGS_ITEM["loadSchemaName"]]}'
|
||||
cur.execute(sql_truncate)
|
||||
print(f'{str(datetime.now())} {log_info} {LOG_LEVEL["i"]} I-MAIN-04 - {settings_list[SETTINGS_ITEM["loadSchemaName"]]} をTRUNCATEしました')
|
||||
except Exception as e:
|
||||
print(f'{str(datetime.now())} {log_info} {LOG_LEVEL["e"]} E-MAIN-99 - エラー内容:{e}')
|
||||
connection_close(conn, bucket_name, target_data_source, target_file_name, log_info)
|
||||
error(bucket_name, target_data_source, target_file_name, log_info)
|
||||
|
||||
# ⑤ 投入データファイルを1行ごとにループする
|
||||
try:
|
||||
print(f'{str(datetime.now())} {log_info} {LOG_LEVEL["i"]} I-MAIN-05 - 投入データ {target_file_name} の読み込みを開始します')
|
||||
target_obj = s3_resource.Object(bucket_name, target_key)
|
||||
target_response = target_obj.get()
|
||||
target_data = io.TextIOWrapper(io.BytesIO(target_response["Body"].read()), encoding=settings_list[SETTINGS_ITEM["charCode"]], newline=LINE_FEED_CODE[settings_list[SETTINGS_ITEM["lineFeedCode"]]])
|
||||
except Exception as e:
|
||||
print(f'{str(datetime.now())} {log_info} {LOG_LEVEL["e"]} E-MAIN-99 - エラー内容:{e}')
|
||||
connection_close(conn, bucket_name, target_data_source, target_file_name, log_info)
|
||||
error(bucket_name, target_data_source, target_file_name, log_info)
|
||||
|
||||
try:
|
||||
process_count = 0 # 処理件数カウンタ
|
||||
normal_count = 0 # 正常終了件数カウンタ
|
||||
warning_count = 0 # ワーニング終了件数カウンター
|
||||
@ -144,12 +134,7 @@ def main(bucket_name, target_key, target_data_source, target_file_name, settings
|
||||
except Exception as e:
|
||||
warning_info = f'{warning_info} {index} ロードスキーマ登録時にエラーが発生しました {line} {e}\n'
|
||||
print(f'{str(datetime.now())} {log_info} {LOG_LEVEL["w"]} W-MAIN-01 {index} ロードスキーマ登録時にエラーが発生しました {line} {e}')
|
||||
except Exception as e:
|
||||
print(f'{str(datetime.now())} {log_info} {LOG_LEVEL["e"]} E-MAIN-99 - エラー内容:{e}')
|
||||
connection_close(conn, bucket_name, target_data_source, target_file_name, log_info)
|
||||
error(bucket_name, target_data_source, target_file_name, log_info)
|
||||
|
||||
try:
|
||||
# ⑥ ⑤の処理結果件数をログ出力する
|
||||
print(f'{str(datetime.now())} {log_info} {LOG_LEVEL["i"]} I-MAIN-07 - 投入データ件数:{process_count} 正常終了件数:{normal_count}')
|
||||
if warning_info:
|
||||
@ -177,12 +162,7 @@ def main(bucket_name, target_key, target_data_source, target_file_name, settings
|
||||
cur.execute(sql)
|
||||
conn.commit()
|
||||
print(f'{str(datetime.now())} {log_info} {LOG_LEVEL["i"]} I-MAIN-10 - 標準SQL:{settings_list[SETTINGS_ITEM["storageSchemaName"]]} のCOMIIT処理が正常終了しました')
|
||||
except Exception as e:
|
||||
print(f'{str(datetime.now())} {log_info} {LOG_LEVEL["e"]} E-MAIN-99 - エラー内容:{e}')
|
||||
connection_close(conn, bucket_name, target_data_source, target_file_name, log_info)
|
||||
error(bucket_name, target_data_source, target_file_name, log_info)
|
||||
|
||||
try:
|
||||
# ⑧ 個別設定ファイルに拡張SQLファイル名が設定されているかチェック
|
||||
print(f'{str(datetime.now())} {log_info} {LOG_LEVEL["i"]} I-MAIN-11 - 拡張SQL設定が存在するかチェックします')
|
||||
if settings_list[SETTINGS_ITEM["exSqlFileName"]]:
|
||||
@ -221,15 +201,19 @@ def main(bucket_name, target_key, target_data_source, target_file_name, settings
|
||||
|
||||
# ⑨ DB接続を終了する
|
||||
connection_close(conn, bucket_name, target_data_source, target_file_name, log_info)
|
||||
|
||||
# ⑩ メイン処理終了ログを出力する
|
||||
print(f'{str(datetime.now())} {log_info} {LOG_LEVEL["i"]} I-MAIN-19 - メイン処理を終了します')
|
||||
except Exception as e:
|
||||
print(f'{str(datetime.now())} {log_info} {LOG_LEVEL["e"]} E-MAIN-99 - エラー内容:{e}')
|
||||
connection_close(conn, bucket_name, target_data_source, target_file_name, log_info)
|
||||
error(bucket_name, target_data_source, target_file_name, log_info)
|
||||
|
||||
try:
|
||||
# ⑩ メイン処理終了ログを出力する
|
||||
print(f'{str(datetime.now())} {log_info} {LOG_LEVEL["i"]} I-MAIN-19 - メイン処理を終了します')
|
||||
|
||||
return warning_info
|
||||
except Exception as e:
|
||||
print(f'{str(datetime.now())} {log_info} {LOG_LEVEL["e"]} E-MAIN-99 - エラー内容:{e}')
|
||||
error(bucket_name, target_data_source, target_file_name, log_info)
|
||||
|
||||
|
||||
def connection_close(conn, bucket_name, target_data_source, target_file_name, log_info):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user