コードの修正
This commit is contained in:
parent
800f79b825
commit
fa408d2a83
@ -1,9 +1,18 @@
|
||||
import os
|
||||
from src.error.exceptions import MaxRunCountReachedException
|
||||
from src.db.database import Database
|
||||
|
||||
DB_USERNAME = os.environ.get("DB_USERNAME")
|
||||
DB_PASSWORD = os.environ.get("DB_PASSWORD")
|
||||
DB_HOST = os.environ.get("DB_HOST")
|
||||
DB_PORT = os.environ.get("DB_PORT")
|
||||
DB_SCHEMA = os.environ.get("DB_SCHEMA")
|
||||
|
||||
# 実消化&アルトマーク_バッチステータス管理テーブルを管理するクラス
|
||||
|
||||
|
||||
class JskultBatchStatusManager:
|
||||
def __init__(self, process_name : str, process_type : str, max_run_count_flg : int, receive_file_count : int):
|
||||
def __init__(self, process_name: str, process_type: str, max_run_count_flg: int, receive_file_count: int):
|
||||
|
||||
# 処理名
|
||||
self._process_name: str = process_name
|
||||
@ -18,13 +27,16 @@ class JskultBatchStatusManager:
|
||||
self._receive_file_count: str = receive_file_count
|
||||
|
||||
# DB接続モジュール(バッチ)のget_instanceを呼び出し設定
|
||||
self._db = Database().get_instance()
|
||||
self._db = Database(DB_USERNAME, DB_PASSWORD, DB_HOST,
|
||||
DB_PORT, DB_SCHEMA).get_instance()
|
||||
|
||||
# 処理ステータスの登録および更新を行う
|
||||
def set_process_status (self, process_status : str):
|
||||
def set_process_status(self, process_status: str):
|
||||
try:
|
||||
self._db.begin()
|
||||
self._db.execute(f"CALL upsert_jskult_batch_status_manage({self._process_name} {self._process_type} {process_status} NULL NULL);")
|
||||
self._db.execute(
|
||||
f"CALL upsert_jskult_batch_status_manage({self._process_name}, {self._process_type}, {process_status}, NULL, NULL);"
|
||||
)
|
||||
self._db.commit()
|
||||
|
||||
except Exception as e:
|
||||
@ -38,7 +50,7 @@ class JskultBatchStatusManager:
|
||||
|
||||
# SELECTの結果からレコード数を取得
|
||||
record_count = self._db.execute_select(
|
||||
f"SELECT * FROM internal07.jskult_batch_status_manage WHERE process_name = {self._process_name} AND process_date = src07.get_syor_date();"
|
||||
f"SELECT * FROM internal07.jskult_batch_status_manage WHERE process_name = {self._process_name} AND process_date = src07.get_syor_date();"
|
||||
).count()
|
||||
|
||||
if record_count == 0:
|
||||
@ -51,7 +63,7 @@ class JskultBatchStatusManager:
|
||||
if self._is_done_data_import():
|
||||
return True
|
||||
|
||||
#最大起動回数に到達していない場合
|
||||
# 最大起動回数に到達していない場合
|
||||
if not self._is_max_run_count_reached:
|
||||
return False
|
||||
|
||||
@ -65,7 +77,7 @@ class JskultBatchStatusManager:
|
||||
|
||||
# SELECTの結果からレコード数を取得
|
||||
record_count = self._db.execute_select(
|
||||
f"SELECT * FROM internal07.jskult_batch_status_manage WHERE process_name = {self._process_name} AND process_date = src07.get_syor_date();"
|
||||
f"SELECT * FROM internal07.jskult_batch_status_manage WHERE process_name = {self._process_name} AND process_date = src07.get_syor_date();"
|
||||
).count()
|
||||
|
||||
if record_count == 0:
|
||||
@ -78,7 +90,7 @@ class JskultBatchStatusManager:
|
||||
if self._is_done_post_process():
|
||||
return True
|
||||
|
||||
#最大起動回数に到達していない場合
|
||||
# 最大起動回数に到達していない場合
|
||||
if not self._is_max_run_count_reached():
|
||||
return False
|
||||
|
||||
@ -88,13 +100,13 @@ class JskultBatchStatusManager:
|
||||
# 最大起動回数に到達した場合にメッセージをスロー
|
||||
raise MaxRunCountReachedException("最大起動回数に到達しました")
|
||||
|
||||
|
||||
# アルトマークデータ連携があったかを確認する
|
||||
|
||||
def is_done_ultmarc_import(self):
|
||||
|
||||
# SELECTの結果からレコード数を取得
|
||||
record_count = self._db.execute_select(
|
||||
f"SELECT * FROM internal07.jskult_batch_status_manage WHERE process_name = 'jskult-batch-ultmarc-io' AND process_date = src07.get_syor_date();"
|
||||
f"SELECT * FROM internal07.jskult_batch_status_manage WHERE process_name = 'jskult-batch-ultmarc-io' AND process_date = src07.get_syor_date();"
|
||||
).count()
|
||||
# アルトマークデータ連携が無かった場合
|
||||
if record_count == 0:
|
||||
@ -108,12 +120,13 @@ class JskultBatchStatusManager:
|
||||
self._db.begin()
|
||||
# SELECTの結果からレコードを取得
|
||||
record = self._db.execute_select(
|
||||
f"SELECT * FROM internal07.jskult_batch_status_manage WHERE process_name = {self._process_name} AND process_date = src07.get_syor_date();"
|
||||
f"SELECT * FROM internal07.jskult_batch_status_manage WHERE process_name = {self._process_name} AND process_date = src07.get_syor_date();"
|
||||
)
|
||||
|
||||
run_count += record[0]['run_count']
|
||||
|
||||
self._db.execute(f"CALL upsert_jskult_batch_status_manage({self._process_name} {self._process_type} NULL {run_count} NULL);")
|
||||
self._db.execute(
|
||||
f"CALL upsert_jskult_batch_status_manage({self._process_name}, {self._process_type}, NULL, {run_count}, NULL);")
|
||||
|
||||
self._db.commit()
|
||||
|
||||
@ -128,11 +141,11 @@ class JskultBatchStatusManager:
|
||||
|
||||
# SELECTの結果からレコード数を取得
|
||||
record_count = self._db.execute_select(
|
||||
f"SELECT * FROM internal07.jskult_batch_status_manage WHERE process_type = {self._process_type} AND process_status = 'done' AND process_date = src07.get_syor_date();"
|
||||
f"SELECT * FROM internal07.jskult_batch_status_manage WHERE process_type = {self._process_type} AND process_status = 'done' AND process_date = src07.get_syor_date();"
|
||||
).count()
|
||||
|
||||
# データ取込数が一致している場合
|
||||
if(self._receive_file_count == record_count):
|
||||
if (self._receive_file_count == record_count):
|
||||
return True
|
||||
|
||||
return False
|
||||
@ -140,40 +153,40 @@ class JskultBatchStatusManager:
|
||||
# 後続処理のすべての処理が完了しているかを判定する
|
||||
def _is_done_post_process(self):
|
||||
|
||||
if not self._is_done_process("jskult-batch-trn-result-data-bio-lot"):
|
||||
return False
|
||||
if not self._is_done_process("jskult-batch-trn-result-data-bio-lot"):
|
||||
return False
|
||||
|
||||
if not self._is_done_process("jskult-batch-mst-inst"):
|
||||
return False
|
||||
if not self._is_done_process("jskult-batch-mst-inst"):
|
||||
return False
|
||||
|
||||
if not self._is_done_process("jskult-batch-dcf-inst-merge-io"):
|
||||
return False
|
||||
|
||||
# 全ての後続処理が完了している場合Trueを返す
|
||||
return True
|
||||
if not self._is_done_process("jskult-batch-dcf-inst-merge-io"):
|
||||
return False
|
||||
|
||||
# 全ての後続処理が完了している場合Trueを返す
|
||||
return True
|
||||
|
||||
# データ取込処理が完了しているかを判定する
|
||||
def _is_done_process(self, process_name : str):
|
||||
|
||||
def _is_done_process(self):
|
||||
|
||||
# SELECTの結果からレコード数を取得
|
||||
record_count = self._db.execute_select(
|
||||
f"SELECT * FROM internal07.jskult_batch_status_manage WHERE process_name = {self._process_name} AND process_status = 'done' AND process_date = src07.get_syor_date();"
|
||||
f"SELECT * FROM internal07.jskult_batch_status_manage WHERE process_name = {self._process_name} AND process_status = 'done' AND process_date = src07.get_syor_date();"
|
||||
).count()
|
||||
|
||||
if(record_count == 0):
|
||||
if (record_count == 0):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
# 起動回数が最大回数に到達しているか判定する
|
||||
|
||||
def _is_max_run_count_reached(self):
|
||||
|
||||
# SELECTの結果からレコード数を取得
|
||||
record = self._db.execute_select(
|
||||
f"SELECT * FROM internal07.jskult_batch_status_manage WHERE process_name = {self._process_name} AND process_date = src07.get_syor_date();"
|
||||
)
|
||||
)
|
||||
|
||||
run_count = record[0]['run_count']
|
||||
|
||||
@ -183,13 +196,13 @@ class JskultBatchStatusManager:
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def _activate_max_run_count_flg(self):
|
||||
try:
|
||||
self._db.begin()
|
||||
|
||||
# 最大起動回数フラグにフラグを立てる
|
||||
self._db.execute(f"CALL upsert_jskult_batch_status_manage({self._process_name} {self._process_type} NULL NULL 1);")
|
||||
self._db.execute(
|
||||
f"CALL upsert_jskult_batch_status_manage({self._process_name}, {self._process_type}, NULL, NULL, 1);")
|
||||
|
||||
self._db.commit()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user