feat: 日付テーブルに関する共通処理実装完了。処理に組み込み。

This commit is contained in:
shimoda.m@nds-tyo.co.jp 2025-05-16 10:20:59 +09:00
parent fbd3bdb590
commit 09307c0142
2 changed files with 39 additions and 26 deletions

View File

@ -2,10 +2,9 @@
from src.aws.s3 import (JskIOBucket, TransferResultOutputBucket, UltmarcBucket,
UltmarcImportBucket)
from src.batch.batch_functions import (
get_batch_statuses, update_batch_processing_flag_in_processing)
from src.error.exceptions import BatchOperationException
from src.logging.get_logger import get_logger
from src.manager.jskult_hdke_tbl_manager import JskultHdkeTblManager
from src.system_var import constants
logger = get_logger('実消化&アルトマークデータ転送')
@ -19,30 +18,23 @@ def exec():
# 転送データリストを初期化する。
transfer_file_lists = {"transfer_list": []}
hdke_tbl_manager = JskultHdkeTblManager()
# ② 日付テーブルのステータスを確認する
try:
# 日次バッチ処置中フラグ、dump処理状態区分、処理日を取得
batch_processing_flag, dump_status_kbn, syor_date = get_batch_statuses()
if not hdke_tbl_manager.can_run_process():
logger.error('日次バッチ処理中またはdump取得が正常終了していないため、データ転送処理を終了します。')
return constants.BATCH_EXIT_CODE_SUCCESS
# 処理日を取得
_, _, syor_date = hdke_tbl_manager.get_batch_statuses()
except BatchOperationException as e:
logger.exception(f'日付テーブル取得(異常終了){e}')
return constants.BATCH_EXIT_CODE_SUCCESS
# 日次バッチ処理中の場合、後続の処理は行わない
if batch_processing_flag == constants.BATCH_ACTF_BATCH_IN_PROCESSING:
logger.error('日次バッチ処理中のため、日次バッチ処理を終了します。')
return constants.BATCH_EXIT_CODE_SUCCESS
# dump取得が正常終了していない場合、後続の処理は行わない
if dump_status_kbn != constants.DUMP_STATUS_KBN_COMPLETE:
logger.error('dump取得が正常終了していないため、日次バッチ処理を終了します。')
return constants.BATCH_EXIT_CODE_SUCCESS
logger.info(f'処理日={syor_date}')
logger.info('I-2 日次バッチ処理中フラグ更新')
# バッチ処理中に更新
try:
update_batch_processing_flag_in_processing()
hdke_tbl_manager.update_batch_process_start()
except BatchOperationException as e:
logger.exception(f'処理フラグ更新(未処理→処理中) エラー(異常終了){e}')
return constants.BATCH_EXIT_CODE_SUCCESS

View File

@ -12,16 +12,13 @@ class JskultHdkeTblManager:
self._db = Database.get_instance()
def get_batch_statuses(self) -> tuple[str, str, str]:
"""日付テーブルから、以下を取得して返す。
- 日次バッチ処理中フラグ
- dump取得状況区分
- 処理日YYYY/MM/DD
"""日次バッチ処理中フラグ、dump取得状況区分、処理日を取得する
Raises:
BatchOperationException: 日付テーブルが取得できないとき何らかのエラーが発生したとき
BatchOperationException: DB操作の何らかのエラー
Returns:
tuple[str, str]: [0]日次バッチ処理中フラグdump取得状況区分
tuple[str, str, str]: [0]日次バッチ処理中フラグ[1]dump取得状況区分[2]処理日
"""
sql = 'SELECT bch_actf, dump_sts_kbn, src07.get_syor_date() AS syor_date FROM src07.hdke_tbl'
try:
@ -51,6 +48,7 @@ class JskultHdkeTblManager:
Raises:
BatchOperationException: DB操作の何らかのエラー
"""
sql = """\
UPDATE src07.hdke_tbl
SET
@ -70,12 +68,13 @@ class JskultHdkeTblManager:
return
def update_batch_process_complete(self):
"""バッチ処理を完了とし、処理日、バッチ処理中フラグ、dump処理状態区分を更新する
def update_batch_process_complete(self) -> None:
"""バッチ正常終了処理時の更新処理
Raises:
BatchOperationException: DB操作の何らかのエラー
"""
sql = """\
UPDATE src07.hdke_tbl
SET
@ -97,5 +96,27 @@ class JskultHdkeTblManager:
finally:
self._db.disconnect()
def can_run_process(self):
pass
def can_run_process(self) -> bool:
"""バッチ処理を起動してよいかを判定する
Raises:
BatchOperationException: DB操作の何らかのエラー
Returns:
bool: バッチ処理を実行して良い場合はTrue
"""
try:
# 日次バッチ処置中フラグ、dump処理状態区分を取得
batch_processing_flag, dump_status_kbn, _ = self.get_batch_statuses()
except DBException as e:
raise BatchOperationException(e)
finally:
self._db.disconnect()
# 日次バッチ処理中の場合、後続の処理は行わない
if batch_processing_flag == constants.BATCH_ACTF_BATCH_IN_PROCESSING:
return False
# dump取得が正常終了していない場合、後続の処理は行わない
if dump_status_kbn != constants.DUMP_STATUS_KBN_COMPLETE:
return False
return True