134 lines
6.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""実消化&アルトマーク 日次バッチ処理"""
from src.aws.s3 import ConfigBucket
from src.batch import parallel_processes
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.batch.dcf_inst_merge import create_dcf_inst_merge
from src.batch.laundering import mst_inst_laundering
from src.batch.ultmarc import ultmarc_process
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
# 稼働日かかどうかを、V実消化非稼働日ファイルをダウンロードして判定
try:
holiday_list_file_path = ConfigBucket().download_holiday_list()
holiday_calendar = CalendarFile(holiday_list_file_path)
batch_context.is_not_business_day = holiday_calendar.compare_date(syor_date)
except Exception as e:
logger.exception(f'V実消化非稼働日ファイルの読み込みに失敗しました。{e}')
return constants.BATCH_EXIT_CODE_SUCCESS
# 調査目的でV実消化稼働日かどうかをログ出力
logger.debug(f'本日は{"V実消化非稼働日です。" if batch_context.is_not_business_day else "V実消化稼働日です。"}')
# バッチ処理中に更新
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_ultmarc_imported else "アルトマーク取込が行われませんでした。"}')
try:
logger.info('V実消化用施設・薬局薬店データ作成処理起動')
ultmarc_process.exec_export()
logger.info('V実消化用施設・薬局薬店データ作成処理終了')
except BatchOperationException as e:
logger.exception(f'V実消化用施設・薬局薬店データ作成処理エラー異常終了{e}')
return constants.BATCH_EXIT_CODE_SUCCESS
logger.info('日次処理V実消化')
try:
logger.info('V実消化取込起動')
logger.info('V実消化取込終了')
except BatchOperationException as e:
logger.exception(f'V実消化取込処理エラー異常終了{e}')
return constants.BATCH_EXIT_CODE_SUCCESS
try:
logger.info('メルク施設マスタ作成:起動')
mst_inst_laundering.exec()
logger.info('メルク施設マスタ作成:終了')
except BatchOperationException as e:
logger.exception(f'メルク施設マスタ作成 エラー(異常終了){e}')
return constants.BATCH_EXIT_CODE_SUCCESS
try:
# 実績生物由来ロット分解と並列処理
logger.info('並列処理(実績更新-生物由来ロット分解):起動')
parallel_processes.exec()
logger.info('並列処理(実績更新-生物由来ロット分解):終了')
except BatchOperationException as e:
logger.exception(f'並列処理(実績更新-生物由来ロット分解)エラー(異常終了){e}')
return constants.BATCH_EXIT_CODE_SUCCESS
try:
logger.info('DCF施設統合マスタ作成起動')
create_dcf_inst_merge.exec()
logger.info('DCF施設統合マスタ作成終了')
except BatchOperationException as e:
logger.exception(f'DCF施設統合マスタ作成エラー異常終了{e}')
return constants.BATCH_EXIT_CODE_SUCCESS
# バッチ処理完了とし、処理日、バッチ処置中フラグ、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