Merge branch 'develop' into feature-NEWDWH2021-1158

This commit is contained in:
shimoda.m@nds-tyo.co.jp 2023-08-03 14:27:31 +09:00
commit c668e4bf76
39 changed files with 75 additions and 45 deletions

View File

@ -1,6 +1,7 @@
import gzip
import os import os
import os.path as path import os.path as path
import tarfile import shutil
import tempfile import tempfile
import boto3 import boto3
@ -134,14 +135,14 @@ class VjskReceiveBucket(S3Bucket):
return temporary_file_path return temporary_file_path
def unzip_data_file(self, filename: str): def unzip_data_file(self, filename: str):
ret = [] temp_dir = os.path.dirname(filename)
with tarfile.open(filename) as tar: decompress_filename = os.path.basename(filename).replace('.gz', '')
temp_dir = os.path.dirname(filename) decompress_file_path = os.path.join(temp_dir, decompress_filename)
tar.extractall(path=temp_dir) with gzip.open(filename, 'rb') as gz:
extracted_files = tar.getnames() with open(decompress_file_path, 'wb') as decompressed_file:
for extracted_file in extracted_files: shutil.copyfileobj(gz, decompressed_file)
file = os.path.join(temp_dir, extracted_file)
ret.append(file) ret = [decompress_file_path]
return ret return ret
def backup_dat_file(self, target_files: list, datetime_key: str): def backup_dat_file(self, target_files: list, datetime_key: str):

View File

@ -60,6 +60,7 @@ def update_batch_processing_flag_in_processing() -> None:
""" """
try: try:
db.connect() db.connect()
db.to_jst()
db.execute(sql, {'in_processing': constants.BATCH_ACTF_BATCH_IN_PROCESSING}) db.execute(sql, {'in_processing': constants.BATCH_ACTF_BATCH_IN_PROCESSING})
except DBException as e: except DBException as e:
raise BatchOperationException(e) raise BatchOperationException(e)
@ -87,6 +88,7 @@ def update_batch_process_complete() -> None:
""" """
try: try:
db.connect() db.connect()
db.to_jst()
db.execute(sql, { db.execute(sql, {
'batch_complete': constants.BATCH_ACTF_BATCH_UNPROCESSED, 'batch_complete': constants.BATCH_ACTF_BATCH_UNPROCESSED,
'dump_unprocessed': constants.DUMP_STATUS_KBN_UNPROCESSED 'dump_unprocessed': constants.DUMP_STATUS_KBN_UNPROCESSED

View File

@ -20,6 +20,7 @@ def exec():
db = Database.get_instance() db = Database.get_instance()
try: try:
db.connect() db.connect()
db.to_jst()
db.begin() db.begin()
logger.debug('DCF施設統合マスタ作成処理開始') logger.debug('DCF施設統合マスタ作成処理開始')
# COM施設からDCF施設統合マスタに登録 # COM施設からDCF施設統合マスタに登録

View File

@ -14,6 +14,7 @@ def exec():
db = Database.get_instance() db = Database.get_instance()
try: try:
db.connect() db.connect()
db.to_jst()
db.begin() db.begin()
logger.debug('DCF施設統合マスタ日次更新処理開始') logger.debug('DCF施設統合マスタ日次更新処理開始')
# DCF施設統合マスタ移行先コードのセット(無効フラグが『0(有効)』) # DCF施設統合マスタ移行先コードのセット(無効フラグが『0(有効)』)

View File

@ -13,6 +13,7 @@ def exec():
db = Database.get_instance() db = Database.get_instance()
try: try:
db.connect() db.connect()
db.to_jst()
logger.debug('##########################') logger.debug('##########################')
logger.debug('START Changing Employee in charge of institution PGM.') logger.debug('START Changing Employee in charge of institution PGM.')
# `emp_chg_inst_lau`をTruncate # `emp_chg_inst_lau`をTruncate

View File

@ -11,6 +11,7 @@ def exec():
db = Database.get_instance(autocommit=True) db = Database.get_instance(autocommit=True)
try: try:
db.connect() db.connect()
db.to_jst()
logger.debug('処理開始') logger.debug('処理開始')
# 卸販売実績テーブル(洗替後)過去5年以前のデータ削除 # 卸販売実績テーブル(洗替後)過去5年以前のデータ削除
_call_sales_lau_delete(db) _call_sales_lau_delete(db)

View File

@ -13,6 +13,7 @@ def exec():
db = Database.get_instance() db = Database.get_instance()
try: try:
db.connect() db.connect()
db.to_jst()
logger.debug('納入先処方元マスタの洗替処理開始') logger.debug('納入先処方元マスタの洗替処理開始')
# ult_ident_presc_lauをTruncate # ult_ident_presc_lauをTruncate
_truncate_ult_ident_presc_lau(db) _truncate_ult_ident_presc_lau(db)

View File

@ -37,6 +37,7 @@ class VjskDataLoadManager:
try: try:
# データベース接続 # データベース接続
db.connect() db.connect()
db.to_jst()
db.execute("SET SESSION sql_mode = 'TRADITIONAL';") db.execute("SET SESSION sql_mode = 'TRADITIONAL';")
# orgをtruncate # orgをtruncate

View File

@ -333,7 +333,7 @@ class VjskReceiveFileMapper:
,t.dsp_odr ,t.dsp_odr
,t.rec_sts_kbn ,t.rec_sts_kbn
,nullif(t.ins_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する ,nullif(t.ins_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,t.upd_dt ,nullif(t.upd_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,SYSDATE() ,SYSDATE()
FROM org05.hld_mst_v AS t FROM org05.hld_mst_v AS t
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
@ -347,7 +347,7 @@ class VjskReceiveFileMapper:
,dsp_odr=t.dsp_odr ,dsp_odr=t.dsp_odr
,rec_sts_kbn=t.rec_sts_kbn ,rec_sts_kbn=t.rec_sts_kbn
,ins_dt=nullif(t.ins_dt, 0) ,ins_dt=nullif(t.ins_dt, 0)
,upd_dt=t.upd_dt ,upd_dt=nullif(t.upd_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,dwh_upd_dt=SYSDATE() ,dwh_upd_dt=SYSDATE()
; ;
""") """)
@ -397,7 +397,7 @@ class VjskReceiveFileMapper:
,t.dsp_odr ,t.dsp_odr
,t.rec_sts_kbn ,t.rec_sts_kbn
,nullif(t.ins_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する ,nullif(t.ins_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,t.upd_dt ,nullif(t.upd_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,SYSDATE() ,SYSDATE()
FROM org05.whs_mst_v AS t FROM org05.whs_mst_v AS t
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
@ -416,7 +416,7 @@ class VjskReceiveFileMapper:
,dsp_odr=t.dsp_odr ,dsp_odr=t.dsp_odr
,rec_sts_kbn=t.rec_sts_kbn ,rec_sts_kbn=t.rec_sts_kbn
,ins_dt=nullif(t.ins_dt, 0) ,ins_dt=nullif(t.ins_dt, 0)
,upd_dt=t.upd_dt ,upd_dt=nullif(t.upd_dt, 0)
,dwh_upd_dt=SYSDATE() ,dwh_upd_dt=SYSDATE()
; ;
""") """)
@ -526,7 +526,7 @@ class VjskReceiveFileMapper:
,t.end_date ,t.end_date
,t.rec_sts_kbn ,t.rec_sts_kbn
,nullif(t.ins_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する ,nullif(t.ins_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,t.upd_dt ,nullif(t.upd_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,SYSDATE() ,SYSDATE()
FROM org05.mkr_org_horizon_v AS t FROM org05.mkr_org_horizon_v AS t
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
@ -575,7 +575,7 @@ class VjskReceiveFileMapper:
,end_date=t.end_date ,end_date=t.end_date
,rec_sts_kbn=t.rec_sts_kbn ,rec_sts_kbn=t.rec_sts_kbn
,ins_dt=nullif(t.ins_dt, 0) ,ins_dt=nullif(t.ins_dt, 0)
,upd_dt=t.upd_dt ,upd_dt=nullif(t.upd_dt, 0)
,dwh_upd_dt=SYSDATE() ,dwh_upd_dt=SYSDATE()
; ;
""") """)
@ -615,7 +615,7 @@ class VjskReceiveFileMapper:
,t.dsp_odr ,t.dsp_odr
,t.rec_sts_kbn ,t.rec_sts_kbn
,nullif(t.ins_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する ,nullif(t.ins_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,t.upd_dt ,nullif(t.upd_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,SYSDATE() ,SYSDATE()
FROM org05.org_cnv_mst_v AS t FROM org05.org_cnv_mst_v AS t
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
@ -629,7 +629,7 @@ class VjskReceiveFileMapper:
,dsp_odr=t.dsp_odr ,dsp_odr=t.dsp_odr
,rec_sts_kbn=t.rec_sts_kbn ,rec_sts_kbn=t.rec_sts_kbn
,ins_dt=nullif(t.ins_dt, 0) ,ins_dt=nullif(t.ins_dt, 0)
,upd_dt=t.upd_dt ,upd_dt=nullif(t.upd_dt, 0)
,dwh_upd_dt=SYSDATE() ,dwh_upd_dt=SYSDATE()
; ;
""") """)
@ -665,7 +665,7 @@ class VjskReceiveFileMapper:
,t.dsp_odr ,t.dsp_odr
,t.rec_sts_kbn ,t.rec_sts_kbn
,nullif(t.ins_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する ,nullif(t.ins_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,t.upd_dt ,nullif(t.upd_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,SYSDATE() ,SYSDATE()
FROM org05.tran_kbn_mst_v AS t FROM org05.tran_kbn_mst_v AS t
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
@ -677,7 +677,7 @@ class VjskReceiveFileMapper:
,dsp_odr=t.dsp_odr ,dsp_odr=t.dsp_odr
,rec_sts_kbn=t.rec_sts_kbn ,rec_sts_kbn=t.rec_sts_kbn
,ins_dt=nullif(t.ins_dt, 0) ,ins_dt=nullif(t.ins_dt, 0)
,upd_dt=t.upd_dt ,upd_dt=nullif(t.upd_dt, 0)
,dwh_upd_dt=SYSDATE() ,dwh_upd_dt=SYSDATE()
; ;
""") """)
@ -743,7 +743,7 @@ class VjskReceiveFileMapper:
,t.fcl_type ,t.fcl_type
,t.rec_sts_kbn ,t.rec_sts_kbn
,nullif(t.ins_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する ,nullif(t.ins_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,t.upd_dt ,nullif(t.upd_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,SYSDATE() ,SYSDATE()
FROM org05.fcl_mst_v AS t FROM org05.fcl_mst_v AS t
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
@ -770,7 +770,7 @@ class VjskReceiveFileMapper:
,fcl_type=t.fcl_type ,fcl_type=t.fcl_type
,rec_sts_kbn=t.rec_sts_kbn ,rec_sts_kbn=t.rec_sts_kbn
,ins_dt=nullif(t.ins_dt, 0) ,ins_dt=nullif(t.ins_dt, 0)
,upd_dt=t.upd_dt ,upd_dt=nullif(t.upd_dt, 0)
,dwh_upd_dt=SYSDATE() ,dwh_upd_dt=SYSDATE()
; ;
""") """)
@ -844,7 +844,7 @@ class VjskReceiveFileMapper:
,t.dsp_odr ,t.dsp_odr
,t.rec_sts_kbn ,t.rec_sts_kbn
,nullif(t.ins_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する ,nullif(t.ins_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,t.upd_dt ,nullif(t.upd_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,SYSDATE() ,SYSDATE()
FROM org05.phm_prd_mst_v AS t FROM org05.phm_prd_mst_v AS t
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
@ -875,7 +875,7 @@ class VjskReceiveFileMapper:
,dsp_odr=t.dsp_odr ,dsp_odr=t.dsp_odr
,rec_sts_kbn=t.rec_sts_kbn ,rec_sts_kbn=t.rec_sts_kbn
,ins_dt=nullif(t.ins_dt, 0) ,ins_dt=nullif(t.ins_dt, 0)
,upd_dt=t.upd_dt ,upd_dt=nullif(t.upd_dt, 0)
,dwh_upd_dt=SYSDATE() ,dwh_upd_dt=SYSDATE()
; ;
""") """)
@ -913,7 +913,7 @@ class VjskReceiveFileMapper:
,t.dsp_odr ,t.dsp_odr
,t.rec_sts_kbn ,t.rec_sts_kbn
,nullif(t.ins_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する ,nullif(t.ins_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,t.upd_dt ,nullif(t.upd_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,SYSDATE() ,SYSDATE()
FROM org05.phm_price_mst_v AS t FROM org05.phm_price_mst_v AS t
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
@ -926,7 +926,7 @@ class VjskReceiveFileMapper:
,dsp_odr=t.dsp_odr ,dsp_odr=t.dsp_odr
,rec_sts_kbn=t.rec_sts_kbn ,rec_sts_kbn=t.rec_sts_kbn
,ins_dt=nullif(t.ins_dt, 0) ,ins_dt=nullif(t.ins_dt, 0)
,upd_dt=t.upd_dt ,upd_dt=nullif(t.upd_dt, 0)
,dwh_upd_dt=SYSDATE() ,dwh_upd_dt=SYSDATE()
; ;
""") """)
@ -1011,7 +1011,7 @@ class VjskReceiveFileMapper:
,t.tel_num ,t.tel_num
,t.rec_sts_kbn ,t.rec_sts_kbn
,nullif(t.ins_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する ,nullif(t.ins_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,t.upd_dt ,nullif(t.upd_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,SYSDATE() ,SYSDATE()
FROM org05.whs_customer_mst_v AS t FROM org05.whs_customer_mst_v AS t
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
@ -1031,7 +1031,7 @@ class VjskReceiveFileMapper:
,tel_num=t.tel_num ,tel_num=t.tel_num
,rec_sts_kbn=t.rec_sts_kbn ,rec_sts_kbn=t.rec_sts_kbn
,ins_dt=nullif(t.ins_dt, 0) ,ins_dt=nullif(t.ins_dt, 0)
,upd_dt=t.upd_dt ,upd_dt=nullif(t.upd_dt, 0)
,dwh_upd_dt=SYSDATE() ,dwh_upd_dt=SYSDATE()
; ;
""") """)
@ -1065,7 +1065,7 @@ class VjskReceiveFileMapper:
,t.start_date ,t.start_date
,t.rec_sts_kbn ,t.rec_sts_kbn
,nullif(t.ins_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する ,nullif(t.ins_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,t.upd_dt ,nullif(t.upd_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,SYSDATE() ,SYSDATE()
FROM org05.mdb_cnv_mst_v AS t FROM org05.mdb_cnv_mst_v AS t
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
@ -1076,7 +1076,7 @@ class VjskReceiveFileMapper:
,start_date=t.start_date ,start_date=t.start_date
,rec_sts_kbn=t.rec_sts_kbn ,rec_sts_kbn=t.rec_sts_kbn
,ins_dt=nullif(t.ins_dt, 0) ,ins_dt=nullif(t.ins_dt, 0)
,upd_dt=t.upd_dt ,upd_dt=nullif(t.upd_dt, 0)
,dwh_upd_dt=SYSDATE() ,dwh_upd_dt=SYSDATE()
; ;
""") """)

View File

@ -180,6 +180,9 @@ class Database:
self.__connection.close() self.__connection.close()
self.__connection = None self.__connection = None
def to_jst(self):
self.execute('SET time_zone = "+9:00"')
def __execute_with_transaction(self, query: str, parameters: dict): def __execute_with_transaction(self, query: str, parameters: dict):
# トランザクションを開始してクエリを実行する # トランザクションを開始してクエリを実行する
with self.__connection.begin(): with self.__connection.begin():

View File

@ -39,6 +39,7 @@ class TestImportFileToDb:
self.db = database self.db = database
self.db.connect() self.db.connect()
self.db.execute("set sql_mode = 'TRADITIONAL';") self.db.execute("set sql_mode = 'TRADITIONAL';")
self.db.to_jst()
# self.db.begin() # self.db.begin()
# testing # testing
@ -1159,7 +1160,7 @@ class TestImportFileToDb:
_import_file_to_db(received_s3_files) _import_file_to_db(received_s3_files)
# 検証 # 検証
assert str(e.value) == "file could not be opened successfully" assert str(e.value) == "Not a gzipped file (b'7z')"
# teardown # teardown
for test_file in test_files: for test_file in test_files:

View File

@ -12,6 +12,7 @@ def exec():
db = Database.get_instance() db = Database.get_instance()
try: try:
db.connect() db.connect()
db.to_jst()
logger.debug('処理開始') logger.debug('処理開始')
# 卸販売実績テーブル(洗替後)作成 # 卸販売実績テーブル(洗替後)作成
_call_sales_lau_upsert(db) _call_sales_lau_upsert(db)

View File

@ -180,6 +180,9 @@ class Database:
self.__connection.close() self.__connection.close()
self.__connection = None self.__connection = None
def to_jst(self):
self.execute('SET time_zone = "+9:00"')
def __execute_with_transaction(self, query: str, parameters: dict): def __execute_with_transaction(self, query: str, parameters: dict):
# トランザクションを開始してクエリを実行する # トランザクションを開始してクエリを実行する
with self.__connection.begin(): with self.__connection.begin():

View File

@ -30,6 +30,8 @@ def exec():
except Exception as e: except Exception as e:
logger.info('DB接続エラーです') logger.info('DB接続エラーです')
raise e raise e
# タイムゾーンをJSTに変更
db.to_jst()
# トランザクションの開始 # トランザクションの開始
db.begin() db.begin()

View File

@ -167,6 +167,9 @@ class Database:
self.__connection.close() self.__connection.close()
self.__connection = None self.__connection = None
def to_jst(self):
self.execute('SET time_zone = "+9:00"')
def __execute_with_transaction(self, query: str, parameters: dict): def __execute_with_transaction(self, query: str, parameters: dict):
# トランザクションを開始してクエリを実行する # トランザクションを開始してクエリを実行する
with self.__connection.begin(): with self.__connection.begin():

View File

@ -1,4 +1,4 @@
FROM python:3.9 FROM python:3.9-bullseye
ENV TZ="Asia/Tokyo" ENV TZ="Asia/Tokyo"

View File

@ -55,6 +55,7 @@ def update_dump_status_kbn_in_processing() -> None:
""" """
try: try:
db.connect() db.connect()
db.to_jst()
db.execute(sql, {'in_processing': constants.BATCH_ACTF_BATCH_IN_PROCESSING}) db.execute(sql, {'in_processing': constants.BATCH_ACTF_BATCH_IN_PROCESSING})
except DBException as e: except DBException as e:
raise BatchOperationException(e) raise BatchOperationException(e)
@ -80,6 +81,7 @@ def update_dump_status_kbn_error() -> None:
""" """
try: try:
db.connect() db.connect()
db.to_jst()
db.execute(sql, { db.execute(sql, {
'dump_unprocessed': constants.DUMP_STATUS_KBN_ERROR 'dump_unprocessed': constants.DUMP_STATUS_KBN_ERROR
}) })
@ -107,6 +109,7 @@ def update_dump_status_kbn_complete() -> None:
""" """
try: try:
db.connect() db.connect()
db.to_jst()
db.execute(sql, { db.execute(sql, {
'dump_unprocessed': constants.DUMP_STATUS_KBN_COMPLETE 'dump_unprocessed': constants.DUMP_STATUS_KBN_COMPLETE
}) })

View File

@ -165,6 +165,9 @@ class Database:
self.__connection.close() self.__connection.close()
self.__connection = None self.__connection = None
def to_jst(self):
self.execute('SET time_zone = "+9:00"')
def __execute_with_transaction(self, query: str, parameters: dict): def __execute_with_transaction(self, query: str, parameters: dict):
# トランザクションを開始してクエリを実行する # トランザクションを開始してクエリを実行する
with self.__connection.begin(): with self.__connection.begin():

View File

@ -23,8 +23,7 @@ def exec():
# 日次バッチ処置中フラグ、dump処理状態区分を取得 # 日次バッチ処置中フラグ、dump処理状態区分を取得
batch_processing_flag, dump_status_kbn = get_batch_statuses() batch_processing_flag, dump_status_kbn = get_batch_statuses()
except BatchOperationException as e: except BatchOperationException as e:
logger.exception(f'日付テーブル取得エラー(異常終了):{e}') raise BatchOperationException(f'日付テーブル取得エラー(異常終了):{e}')
return constants.BATCH_EXIT_CODE_SUCCESS
# 日次バッチ処理中の場合、処理は行わない # 日次バッチ処理中の場合、処理は行わない
if batch_processing_flag == constants.BATCH_ACTF_BATCH_IN_PROCESSING: if batch_processing_flag == constants.BATCH_ACTF_BATCH_IN_PROCESSING:
@ -45,8 +44,7 @@ def exec():
try: try:
update_dump_status_kbn_in_processing() update_dump_status_kbn_in_processing()
except BatchOperationException as e: except BatchOperationException as e:
logger.exception(f'dump処理状態区分更新(未処理→処理中) エラー(異常終了):{e}') raise BatchOperationException(f'dump処理状態区分更新(未処理→処理中) エラー(異常終了):{e}')
return constants.BATCH_EXIT_CODE_SUCCESS
# MySQL接続情報を作成する # MySQL接続情報を作成する
my_cnf_file_content = f""" my_cnf_file_content = f"""
@ -93,25 +91,21 @@ def exec():
# パイプラインを実行し、エラーハンドリング # パイプラインを実行し、エラーハンドリング
_, error = mysqldump_process.communicate() _, error = mysqldump_process.communicate()
if mysqldump_process.returncode != 0: if mysqldump_process.returncode != 0:
logger.error(f'`mysqldump`実行時にエラーが発生しました。{"" if error is None else error.decode("utf-8")}') raise BatchOperationException(f'`mysqldump`実行時にエラーが発生しました。{"" if error is None else error.decode("utf-8")}')
return constants.BATCH_EXIT_CODE_SUCCESS
_, error = gzip_process.communicate() _, error = gzip_process.communicate()
if gzip_process.returncode != 0: if gzip_process.returncode != 0:
logger.error(f'`gzip`実行時にエラーが発生しました。{"" if error is None else error.decode("utf-8")}') raise BatchOperationException(f'`gzip`実行時にエラーが発生しました。{"" if error is None else error.decode("utf-8")}')
return constants.BATCH_EXIT_CODE_SUCCESS
_, error = s3_cp_process.communicate() _, error = s3_cp_process.communicate()
if s3_cp_process.returncode != 0: if s3_cp_process.returncode != 0:
logger.error(f'`aws s3 cp`実行時にエラーが発生しました。{"" if error is None else error.decode("utf-8")}') raise BatchOperationException(f'`aws s3 cp`実行時にエラーが発生しました。{"" if error is None else error.decode("utf-8")}')
return constants.BATCH_EXIT_CODE_SUCCESS
# dump処理状態区分を正常終了に更新 # dump処理状態区分を正常終了に更新
try: try:
update_dump_status_kbn_complete() update_dump_status_kbn_complete()
except BatchOperationException as e: except BatchOperationException as e:
logger.exception(f'dump処理状態区分更新(処理中→正常終了) エラー(異常終了):{e}') raise BatchOperationException(f'dump処理状態区分更新(処理中→正常終了) エラー(異常終了):{e}')
return constants.BATCH_EXIT_CODE_SUCCESS
logger.info('日次バッチ処理前DBダンプ取得終了正常終了') logger.info('日次バッチ処理前DBダンプ取得終了正常終了')
logger.info(f'出力ファイルパス: {s3_file_path}') logger.info(f'出力ファイルパス: {s3_file_path}')

View File

@ -1,4 +1,4 @@
FROM python:3.9 FROM python:3.9-bullseye
ENV TZ="Asia/Tokyo" ENV TZ="Asia/Tokyo"

View File

@ -180,6 +180,9 @@ class Database:
self.__connection.close() self.__connection.close()
self.__connection = None self.__connection = None
def to_jst(self):
self.execute('SET time_zone = "+9:00"')
def __execute_with_transaction(self, query: str, parameters: dict): def __execute_with_transaction(self, query: str, parameters: dict):
# トランザクションを開始してクエリを実行する # トランザクションを開始してクエリを実行する
with self.__connection.begin(): with self.__connection.begin():

View File

@ -30,6 +30,7 @@ class MasterMainteEmpChgInstFunction(metaclass=ABCMeta):
error_list = [] error_list = []
try: try:
self.emp_chginst_repository.connect() self.emp_chginst_repository.connect()
self.emp_chginst_repository.to_jst()
self.emp_chginst_repository.begin() self.emp_chginst_repository.begin()
(result_message, error_list) = self.write_emp_chg_inst_table() (result_message, error_list) = self.write_emp_chg_inst_table()
if len(error_list) > 0: if len(error_list) > 0:

View File

@ -14,6 +14,9 @@ class EmpChgInstRepository(BaseRepository):
def connect(self): def connect(self):
self._database.connect() self._database.connect()
def to_jst(self):
self._database.to_jst()
def begin(self): def begin(self):
self._database.begin() self._database.begin()
@ -110,7 +113,7 @@ class EmpChgInstRepository(BaseRepository):
SET SET
emp_cd = :emp_cd, emp_cd = :emp_cd,
updater = :update_user_name, updater = :update_user_name,
update_date = now() update_date = NOW()
where where
inst_cd = :inst_cd inst_cd = :inst_cd
and ta_cd = :ta_cd and ta_cd = :ta_cd

View File

@ -149,6 +149,7 @@ class MasterMainteService(BaseService):
def copy_data_real_to_dummy(self) -> TableOverrideViewModel: def copy_data_real_to_dummy(self) -> TableOverrideViewModel:
try: try:
self.emp_chginst_repository.connect() self.emp_chginst_repository.connect()
self.emp_chginst_repository.to_jst()
self.emp_chginst_repository.begin() self.emp_chginst_repository.begin()
self.emp_chginst_repository.delete_dummy_table() self.emp_chginst_repository.delete_dummy_table()
self.emp_chginst_repository.copy_real_to_dummy() self.emp_chginst_repository.copy_real_to_dummy()