89 lines
4.5 KiB
Python
89 lines
4.5 KiB
Python
"""実消化&アルトマーク 月次バッチ処理"""
|
|
|
|
from src.aws.s3 import ConfigBucket
|
|
from src.batch.batch_functions import (
|
|
get_batch_statuses, update_batch_process_complete,
|
|
update_batch_processing_flag_in_processing)
|
|
from src.batch.common.batch_context import BatchContext
|
|
from src.batch.common.calendar_file import CalendarFile
|
|
from src.error.exceptions import BatchOperationException
|
|
from src.logging.get_logger import get_logger
|
|
from src.system_var import constants
|
|
|
|
logger = get_logger('月次処理コントロール')
|
|
|
|
# バッチ共通設定を取得
|
|
batch_context = BatchContext.get_instance()
|
|
|
|
|
|
def exec():
|
|
try:
|
|
logger.info('月次バッチ:開始')
|
|
try:
|
|
# 月次バッチ処置中フラグ、dump処理状態区分、処理日を取得
|
|
batch_processing_flag, dump_status_kbn, syor_date = 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}')
|
|
# バッチ共通設定に処理日を追加
|
|
batch_context.syor_date = syor_date
|
|
|
|
# 稼働日かかどうかを、実消化&アルトマーク月次バッチ稼働日ファイルをダウンロードして判定
|
|
try:
|
|
arisj_output_day_list_file_path = ConfigBucket().download_arisj_output_day_list()
|
|
arisj_output_day_calendar = CalendarFile(arisj_output_day_list_file_path)
|
|
batch_context.is_not_business_monthly = arisj_output_day_calendar.compare_date(syor_date)
|
|
except Exception as e:
|
|
logger.exception(f'実消化&アルトマーク月次バッチ稼働日ファイルの読み込みに失敗しました。{e}')
|
|
return constants.BATCH_EXIT_CODE_SUCCESS
|
|
|
|
# 調査目的でV実消化稼働日かどうかをログ出力
|
|
logger.debug(f'本日は{"実消化&アルトマーク月次バッチ稼働日です。" if batch_context.is_not_business_monthly else "実消化&アルトマーク月次バッチ非稼働日です。"}')
|
|
|
|
# バッチ処理中に更新
|
|
try:
|
|
update_batch_processing_flag_in_processing()
|
|
except BatchOperationException as e:
|
|
logger.exception(f'処理フラグ更新(未処理→処理中) エラー(異常終了){e}')
|
|
return constants.BATCH_EXIT_CODE_SUCCESS
|
|
|
|
try:
|
|
logger.info('月次バッチ:起動')
|
|
# ultmarc_process.exec_import()
|
|
logger.info('月次バッチ:終了')
|
|
except BatchOperationException as e:
|
|
logger.exception(f'月次バッチ処理エラー(異常終了){e}')
|
|
return constants.BATCH_EXIT_CODE_SUCCESS
|
|
|
|
# 調査目的で月次バッチが行われたかどうかをログ出力
|
|
logger.debug(f'{"月次バッチが行われました。" if batch_context.is_not_business_monthly else "月次バッチが行われませんでした。"}')
|
|
|
|
# バッチ処理完了とし、処理日、バッチ処置中フラグ、dump取得状態区分を更新
|
|
logger.info('業務日付更新・バッチステータスリフレッシュ:起動')
|
|
try:
|
|
update_batch_process_complete()
|
|
except BatchOperationException as e:
|
|
logger.exception(f'業務日付更新・バッチステータスリフレッシュ エラー(異常終了){e}')
|
|
return constants.BATCH_EXIT_CODE_SUCCESS
|
|
logger.info('業務日付更新・バッチステータスリフレッシュ:終了')
|
|
|
|
# 正常終了を保守ユーザーに通知
|
|
logger.info('[NOTICE]月次バッチ:終了(正常終了)')
|
|
return constants.BATCH_EXIT_CODE_SUCCESS
|
|
|
|
except Exception as e:
|
|
logger.exception(f'月次バッチ処理中に想定外のエラーが発生しました {e}')
|
|
raise e
|