diff options
author | Satoshi Fujii <fujii-satoshi@jp.fujitsu.com> | 2021-10-15 05:57:24 +0000 |
---|---|---|
committer | Satoshi Fujii <fujii-satoshi@jp.fujitsu.com> | 2021-10-21 09:48:00 +0000 |
commit | 4c058689904178714211f38bc5e5e083eaffadbf (patch) | |
tree | bbb11bbbfb212baa26a05a3d02491b04eb8889f0 /miss_htbt_service/cbs_polling.py | |
parent | 8ea70b60efac67f8b4ad4be8b8018a946f551d06 (diff) |
Fix cbs polling process startup failure
cbs polling process sometimes failed to start by `relation
"hb_common" does not exist` error.
The polling process tries to read hb_common table on startup,
but the process is created before the parent process creates
hb_common table. So the error may occur in race condition.
cbs_polling process must be started after `hb_common` table populated.
Signed-off-by: Satoshi Fujii <fujii-satoshi@jp.fujitsu.com>
Issue-ID: DCAEGEN2-2944
Change-Id: Iee682b62a385dfaf2ec1355e781cda9c3def23c0
Diffstat (limited to 'miss_htbt_service/cbs_polling.py')
-rw-r--r-- | miss_htbt_service/cbs_polling.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/miss_htbt_service/cbs_polling.py b/miss_htbt_service/cbs_polling.py index 8d5af09..3832b71 100644 --- a/miss_htbt_service/cbs_polling.py +++ b/miss_htbt_service/cbs_polling.py @@ -33,7 +33,7 @@ import get_logger _logger = get_logger.get_logger(__name__) -def pollCBS(current_pid): +def poll_cbs(current_pid: int) -> None: jsfile = db.fetch_json_file() ip_address, port_num, user_name, password, db_name, cbs_polling_required, cbs_polling_interval = db.read_hb_properties(jsfile) hbc_pid, hbc_state, hbc_srcName, hbc_time = db.read_hb_common(user_name, password, ip_address, port_num, db_name) @@ -50,18 +50,20 @@ def pollCBS(current_pid): hbc_pid, hbc_state, hbc_srcName, hbc_time = db.read_hb_common(user_name, password, ip_address, port_num, db_name) source_name = socket.gethostname() source_name = source_name + "-" + str(os.getenv('SERVICE_NAME', "")) - result = True - if int(current_pid) == int(hbc_pid) and source_name == hbc_srcName and hbc_state == "RUNNING": + if current_pid == int(hbc_pid) and source_name == hbc_srcName and hbc_state == "RUNNING": _logger.info("CBSP:ACTIVE Instance:Change the state to RECONFIGURATION") state = "RECONFIGURATION" update_flg = 1 db.create_update_hb_common(update_flg, hbc_pid, state, user_name, password, ip_address, port_num, db_name) else: _logger.info("CBSP:Inactive instance or hb_common state is not RUNNING") - return result -if __name__ == "__main__": - current_pid = sys.argv[1] +def cbs_polling_loop(current_pid: int): while True: - pollCBS(current_pid) + poll_cbs(current_pid) + + +if __name__ == "__main__": + parent_pid = int(sys.argv[1]) + cbs_polling_loop(parent_pid) |