feat: lambda_handlerに例外処理追加、コメント追加、未受領チェック関数名修正
This commit is contained in:
parent
8ca83fcc74
commit
41542bbd9d
@ -129,8 +129,16 @@ def make_failure_item_on_error(message_id: str) -> dict[str, str]:
|
|||||||
return {"itemIdentifier": message_id}
|
return {"itemIdentifier": message_id}
|
||||||
|
|
||||||
|
|
||||||
def unreceive_check(records: list, execute_month: str) -> tuple[list[dict[str, str]], list[str]]:
|
def encise_data_unreceive_check(records: list, execute_month: str) -> tuple[list[dict[str, str]], list[str]]:
|
||||||
|
"""Enciseデータ未受領チェック
|
||||||
|
|
||||||
|
Args:
|
||||||
|
records (list): SQS Eventのレコードリスト
|
||||||
|
execute_month (str): 処理起動年月
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
tuple[list[dict[str, str]], list[str]]: 失敗メッセージIdのリスト, 成功メッセージIdのリスト
|
||||||
|
"""
|
||||||
batch_item_failures = []
|
batch_item_failures = []
|
||||||
batch_item_success = []
|
batch_item_success = []
|
||||||
|
|
||||||
@ -146,7 +154,7 @@ def unreceive_check(records: list, execute_month: str) -> tuple[list[dict[str, s
|
|||||||
logger.info(f'受信したメッセージは既に処理済みのため、処理をスキップします。メッセージID: {message_id}')
|
logger.info(f'受信したメッセージは既に処理済みのため、処理をスキップします。メッセージID: {message_id}')
|
||||||
continue
|
continue
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"E-02-01 メッセージ重複チェック処理に失敗しました エラー内容:{e}")
|
logger.exception(f"E-02-01 メッセージ重複チェック処理に失敗しました エラー内容:{e}")
|
||||||
batch_item_failures.append(make_failure_item_on_error(message_id))
|
batch_item_failures.append(make_failure_item_on_error(message_id))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -166,7 +174,7 @@ def unreceive_check(records: list, execute_month: str) -> tuple[list[dict[str, s
|
|||||||
)
|
)
|
||||||
logger.info('I-03-02 受領チェック対象ファイルリストを読み込みました')
|
logger.info('I-03-02 受領チェック対象ファイルリストを読み込みました')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"E-03-01 受領チェック対象ファイルリストの読み込みに失敗しました エラー内容:{e}")
|
logger.exception(f"E-03-01 受領チェック対象ファイルリストの読み込みに失敗しました エラー内容:{e}")
|
||||||
batch_item_failures.append(make_failure_item_on_error(message_id))
|
batch_item_failures.append(make_failure_item_on_error(message_id))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -241,7 +249,7 @@ def unreceive_check(records: list, execute_month: str) -> tuple[list[dict[str, s
|
|||||||
mail_title_without_line_break = mail_title.splitlines()[0]
|
mail_title_without_line_break = mail_title.splitlines()[0]
|
||||||
logger.info('I-05-04 通知メール(タイトル)テンプレートファイルを読み込みました')
|
logger.info('I-05-04 通知メール(タイトル)テンプレートファイルを読み込みました')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f'E-05-01 通知メール(タイトル)テンプレートファイルの読み込みに失敗しました エラー内容:{e}')
|
logger.exception(f'E-05-01 通知メール(タイトル)テンプレートファイルの読み込みに失敗しました エラー内容:{e}')
|
||||||
batch_item_failures.append(make_failure_item_on_error(message_id))
|
batch_item_failures.append(make_failure_item_on_error(message_id))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -259,7 +267,7 @@ def unreceive_check(records: list, execute_month: str) -> tuple[list[dict[str, s
|
|||||||
mail_body = substitute_mail_template(mail_body_template, receive_timing, mail_message)
|
mail_body = substitute_mail_template(mail_body_template, receive_timing, mail_message)
|
||||||
logger.info('I-05-06 通知メール(本文)テンプレートファイルを読み込みました')
|
logger.info('I-05-06 通知メール(本文)テンプレートファイルを読み込みました')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f'E-05-02 通知メール(本文)テンプレートファイルの読み込みに失敗しました エラー内容:{e}')
|
logger.exception(f'E-05-02 通知メール(本文)テンプレートファイルの読み込みに失敗しました エラー内容:{e}')
|
||||||
batch_item_failures.append(make_failure_item_on_error(message_id))
|
batch_item_failures.append(make_failure_item_on_error(message_id))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -274,7 +282,7 @@ def unreceive_check(records: list, execute_month: str) -> tuple[list[dict[str, s
|
|||||||
|
|
||||||
batch_item_success.append(message_id)
|
batch_item_success.append(message_id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f'E-99 想定外のエラーが発生しました エラー内容:{e}')
|
logger.exception(f'E-99 想定外のエラーが発生しました エラー内容:{e}')
|
||||||
batch_item_failures.append(make_failure_item_on_error(message_id))
|
batch_item_failures.append(make_failure_item_on_error(message_id))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -282,24 +290,29 @@ def unreceive_check(records: list, execute_month: str) -> tuple[list[dict[str, s
|
|||||||
|
|
||||||
|
|
||||||
def lambda_handler(event, context):
|
def lambda_handler(event, context):
|
||||||
# ① 処理開始ログを出力する
|
try:
|
||||||
logger.info('I-01-01 処理開始 Enciseデータ受領チェック処理')
|
# ① 処理開始ログを出力する
|
||||||
# 処理稼働年月を取得しメモリに保持する
|
logger.info('I-01-01 処理開始 Enciseデータ受領チェック処理')
|
||||||
execute_date_today = datetime.date.today()
|
# 処理稼働年月を取得しメモリに保持する
|
||||||
execute_month = execute_date_today.strftime('%Y/%m')
|
execute_date_today = datetime.date.today()
|
||||||
logger.info(f'I-01-02 処理稼働月:{execute_month}')
|
execute_month = execute_date_today.strftime('%Y/%m')
|
||||||
# 処理失敗メッセージIDリストをメモリに保持する(初期値=空のリスト)
|
logger.info(f'I-01-02 処理稼働月:{execute_month}')
|
||||||
batch_item_failures = []
|
# 処理失敗メッセージIDリストをメモリに保持する(初期値=空のリスト)
|
||||||
# 処理成功メッセージIDリストをメモリに保持する(初期値=空のリスト)
|
batch_item_failures = []
|
||||||
batch_item_success = []
|
# 処理成功メッセージIDリストをメモリに保持する(初期値=空のリスト)
|
||||||
# ② SQSメッセージ重複排除処理を行う
|
batch_item_success = []
|
||||||
logger.info('I-02-01 メッセージ処理開始')
|
# ② SQSメッセージ重複排除処理を行う
|
||||||
batch_item_failures, batch_item_success = unreceive_check(event["Records"], execute_month)
|
logger.info('I-02-01 メッセージ処理開始')
|
||||||
logger.info('I-06-01 すべてのメッセージの処理完了')
|
batch_item_failures, batch_item_success = encise_data_unreceive_check(event["Records"], execute_month)
|
||||||
|
logger.info('I-06-01 すべてのメッセージの処理完了')
|
||||||
|
|
||||||
# ⑦ メッセージを処理済として、以下のDynamoDBテーブルに記録する
|
# ⑦ メッセージを処理済として、以下のDynamoDBテーブルに記録する
|
||||||
push_success_messages_to_dynamo_db(batch_item_success)
|
push_success_messages_to_dynamo_db(batch_item_success)
|
||||||
logger.info('I-07-01 処理済みメッセージIDの記録完了')
|
logger.info('I-07-01 処理済みメッセージIDの記録完了')
|
||||||
logger.info('I-07-02 処理終了 Enciseデータ受領チェック処理')
|
logger.info('I-07-02 処理終了 Enciseデータ受領チェック処理')
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.exception(f'E-99 想定外のエラーが発生しました エラー内容:{e}')
|
||||||
|
raise e
|
||||||
|
|
||||||
return batch_item_failures
|
return batch_item_failures
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user