feat: ログ追加、例外メッセージもちょっと修正
This commit is contained in:
parent
cd15c199ec
commit
8fac8401bf
@ -7,6 +7,7 @@ from src.batch.ultmarc.datfile import DatFile
|
||||
from src.batch.ultmarc.utmp_tables.ultmarc_table_mapper_factory import \
|
||||
UltmarcTableMapperFactory
|
||||
from src.db.database import Database
|
||||
from src.error.exceptions import DBException
|
||||
from src.logging.get_logger import get_logger
|
||||
|
||||
logger = get_logger('アルトマークデータ保管')
|
||||
@ -21,6 +22,7 @@ def dat_insert_control():
|
||||
db.connect()
|
||||
# ファイル単位でトランザクションを行う
|
||||
db.begin()
|
||||
logger.info('Transaction BEGIN')
|
||||
# datファイルをS3から取得する
|
||||
dat_file_list = ultmarc_bucket.list_edi_file()
|
||||
# ファイルがない場合は処理せず、正常終了とする
|
||||
@ -66,8 +68,7 @@ def dat_insert_control():
|
||||
# これいる??
|
||||
if log_count % 5000 == 0:
|
||||
logger.info(f'Count: {log_count}')
|
||||
except Exception as e:
|
||||
# TODO: ログちゃんとする
|
||||
except DBException as e:
|
||||
logger.warning(e)
|
||||
record = line.records
|
||||
log_message = ','.join([f'"{r}"' for r in record])
|
||||
@ -75,6 +76,7 @@ def dat_insert_control():
|
||||
dat_file.count_up_error()
|
||||
# すべての行を登録終えたらコミットする
|
||||
db.commit()
|
||||
logger.info('Transaction COMMIT')
|
||||
logger.info(f'datInsert RESULT')
|
||||
logger.info(f'SUCCESS_COUNT={dat_file.success_count}')
|
||||
logger.info(f'ERROR_COUNT={dat_file.error_count}')
|
||||
|
||||
@ -81,7 +81,10 @@ class Database:
|
||||
Raises:
|
||||
DBException: 接続失敗
|
||||
"""
|
||||
self.__connection = self.__engine.connect()
|
||||
try:
|
||||
self.__connection = self.__engine.connect()
|
||||
except Exception as e:
|
||||
raise DBException(f'SQL Error: {e}')
|
||||
|
||||
def execute_select(self, select_query: str, parameters=None) -> list[dict]:
|
||||
"""SELECTクエリを実行します。
|
||||
@ -108,7 +111,7 @@ class Database:
|
||||
# トランザクションが明示的に開始していない場合は、クエリ単位でトランザクションをbegin-commitする。
|
||||
result = self.__execute_with_transaction(select_query, parameters)
|
||||
except Exception as e:
|
||||
raise DBException(e)
|
||||
raise DBException(f'SQL Error: {e}')
|
||||
|
||||
result_rows = result.mappings().all()
|
||||
return result_rows
|
||||
@ -138,7 +141,7 @@ class Database:
|
||||
# トランザクションが明示的に開始していない場合は、クエリ単位でトランザクションをbegin-commitする。
|
||||
result = self.__execute_with_transaction(query, parameters)
|
||||
except Exception as e:
|
||||
raise DBException(e)
|
||||
raise DBException(f'SQL Error: {e}')
|
||||
|
||||
return result
|
||||
|
||||
|
||||
@ -4,11 +4,14 @@ from tenacity import RetryError
|
||||
class MeDaCaException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class DBException(MeDaCaException):
|
||||
pass
|
||||
|
||||
|
||||
class BatchOperationException(MeDaCaException):
|
||||
pass
|
||||
|
||||
|
||||
class MaxRetryExceededException(MeDaCaException, RetryError):
|
||||
pass
|
||||
pass
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user