diff --git a/ecs/jskult-batch/src/manager/jskult_batch_run_manager.py b/ecs/jskult-batch/src/manager/jskult_batch_run_manager.py index 3a55f7b9..2a727e10 100644 --- a/ecs/jskult-batch/src/manager/jskult_batch_run_manager.py +++ b/ecs/jskult-batch/src/manager/jskult_batch_run_manager.py @@ -1,28 +1,39 @@ +import os +from datetime import datetime, timezone + +import boto3 + +TABLE_NAME = 'mbj-newdwh2021-staging-jskult-batch-run-manage' + +dynamodb = boto3.client('dynamodb') + + class JskultBatchRunManager: def __init__(self, execution_id: str): self._execution_id: str = execution_id - + + # バッチ処理ステータスをsuccessで登録および更新を行う def batch_success(self): - try: - self._put_dynamodb_record('success') - except Exception as e: - raise e - + self._put_dynamodb_record('success') + + # バッチ処理ステータスをfailedで登録および更新を行う def batch_failed(self): - try: - self._put_dynamodb_record('failed') - except Exception as e: - raise e + self._put_dynamodb_record('failed') + # バッチ処理ステータスをretryで登録および更新を行う def batch_retry(self): - try: - self._put_dynamodb_record('retry') - except Exception as e: - raise e + self._put_dynamodb_record('retry') - def _put_dynamodb_record(self, execution_id: str): - try: - self._execution_id = execution_id - # TODO バッチ実行管理テーブルの登録、更新(upsert) - except Exception as e: - raise e \ No newline at end of file + def _put_dynamodb_record(self, record: str): + # バッチ実行管理テーブルの登録、更新(upsert) + now = int(datetime.now(timezone.utc).timestamp() * 1000) + + options = { + 'TableName': TABLE_NAME, + 'Item': { + 'execution_id': {'S': self._execution_id}, + 'status': {'S': record}, + 'createdAt': {'N': str(now)}, + }, + } + dynamodb.put_item(**options)