From 5cadb1a466be0371aa80f71c9c09635b742e3818 Mon Sep 17 00:00:00 2001 From: "shimoda.m@nds-tyo.co.jp" Date: Tue, 13 Feb 2024 14:02:08 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20DynamoDB=E3=83=86=E3=83=BC=E3=83=96?= =?UTF-8?q?=E3=83=AB=E3=81=AE=E3=83=AC=E3=82=B3=E3=83=BC=E3=83=89=E6=9C=89?= =?UTF-8?q?=E5=8A=B9=E6=9C=9F=E9=99=90=E7=94=A8=E3=81=AE=E9=A0=85=E7=9B=AE?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../encise-data-unreceive-check.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lambda/encise-data-unreceive-check/encise-data-unreceive-check.py b/lambda/encise-data-unreceive-check/encise-data-unreceive-check.py index 130e0a9a..e4e26de8 100644 --- a/lambda/encise-data-unreceive-check/encise-data-unreceive-check.py +++ b/lambda/encise-data-unreceive-check/encise-data-unreceive-check.py @@ -17,7 +17,7 @@ LOG_LEVEL = os.environ["LOG_LEVEL"] MAIL_TEMPLATE_FOLDER_PATH = os.environ["MAIL_TEMPLATE_FOLDER_PATH"] MBJ_NOTICE_TOPIC = os.environ["MBJ_NOTICE_TOPIC"] PROCESSED_MESSAGE_DYNAMODB_TABLE_NAME = os.environ["PROCESSED_MESSAGE_DYNAMODB_TABLE_NAME"] -PROCESSED_MESSAGE_EXPIRES_PERIOD = os.environ["PROCESSED_MESSAGE_EXPIRES_PERIOD"] +PROCESSED_MESSAGE_EXPIRES_PERIOD = int(os.environ["PROCESSED_MESSAGE_EXPIRES_PERIOD"]) TZ = os.environ["TZ"] # 定数 @@ -79,7 +79,7 @@ def is_duplicate_message(message_id: str) -> bool: )["Count"] != 0 -def push_success_messages_to_dynamo_db(batch_item_success: list[str]) -> bool: +def put_success_messages_to_dynamo_db(batch_item_success: list[str]) -> bool: """処理済みのSQSメッセージIdをDynamoDBにPushする Args: @@ -88,10 +88,19 @@ def push_success_messages_to_dynamo_db(batch_item_success: list[str]) -> bool: Returns: bool: 登録成功の場合、True """ + + # レコードの有効期限を算出 + now = datetime.datetime.now(ZoneInfo(TZ)) + record_expiration_datetime = now + datetime.timedelta(minutes=PROCESSED_MESSAGE_EXPIRES_PERIOD) + record_expiration_time = record_expiration_datetime.timestamp() + for message_id in batch_item_success: dynamodb_client.put_item( TableName=PROCESSED_MESSAGE_DYNAMODB_TABLE_NAME, - Item={'message_id': {'S': message_id}} + Item={ + 'message_id': {'S': message_id}, + 'record_expiration_time': {'N': f'{record_expiration_time}'} + } ) return True @@ -305,7 +314,7 @@ def lambda_handler(event, context): logger.info('I-06-01 すべてのメッセージの処理完了') # ⑦ メッセージを処理済として、以下のDynamoDBテーブルに記録する - push_success_messages_to_dynamo_db(batch_item_success) + put_success_messages_to_dynamo_db(batch_item_success) logger.info('I-07-01 処理済みメッセージIDの記録完了') logger.info('I-07-02 処理終了 Enciseデータ受領チェック処理')