From 253e48694a54c45fbe747caf9acef683ac91c676 Mon Sep 17 00:00:00 2001 From: hide_d Date: Wed, 6 May 2020 20:56:13 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95,=20?= =?UTF-8?q?=EB=B0=98=EB=B3=B5=20=EB=8F=84=EA=B5=AC=20=EA=B0=95=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/ResetHelper.php | 5 ++++ hwe/sql/schema.sql | 3 +- src/run_daemon.py | 61 +++++++++++++++++++++++++++------------ 3 files changed, 49 insertions(+), 20 deletions(-) diff --git a/hwe/sammo/ResetHelper.php b/hwe/sammo/ResetHelper.php index c30c4432..ddaecf07 100644 --- a/hwe/sammo/ResetHelper.php +++ b/hwe/sammo/ResetHelper.php @@ -100,6 +100,11 @@ class ResetHelper{ ], true ); + copy( + $servRoot.'/d_setting/GameConst.orig.php', + $servRoot.'/d_setting/GameConst.php', + ); + if($mysqli_obj->multi_query(file_get_contents($servRoot.'/sql/reset.sql'))){ while(true){ if (!$mysqli_obj->more_results()) { diff --git a/hwe/sql/schema.sql b/hwe/sql/schema.sql index a988cc8b..43aae28e 100644 --- a/hwe/sql/schema.sql +++ b/hwe/sql/schema.sql @@ -299,8 +299,7 @@ CREATE TABLE IF NOT EXISTS `ng_games` ( `season` INT(11) NOT NULL, `scenario` INT(11) NOT NULL, `scenario_name` TEXT NOT NULL, - `env` TEXT NOT NULL CHECK (json_valid(`aux`)), - CHECK (JSON_VALID(`env`)), + `env` TEXT NOT NULL CHECK (json_valid(`env`)), PRIMARY KEY (`id`), UNIQUE INDEX `server_id` (`server_id`), INDEX `date` (`date`) diff --git a/src/run_daemon.py b/src/run_daemon.py index 8c298979..cb05d5e4 100644 --- a/src/run_daemon.py +++ b/src/run_daemon.py @@ -7,11 +7,28 @@ import urllib.request import concurrent.futures from datetime import datetime +ONE_FILE_LOOP_SEC = 60 +ONE_LOOP_TIME_SEC = 6 +RETRY_SEC = 2 + +def getCurrentMillisecTime(): + return int(time.time() * 1000) + + def run(webPath): - now = datetime.now() - print(now.strftime("%Y-%m-%d %H:%M:%S"), webPath) - obj = urllib.request.urlopen(webPath) - obj.read() + for _ in range(5): + now = datetime.now() + print(now.strftime("%Y-%m-%d %H:%M:%S"), webPath) + startTime = getCurrentMillisecTime() + + obj = urllib.request.urlopen(webPath) + obj.read() + + timeGap = getCurrentMillisecTime() - startTime + if timeGap < RETRY_SEC * 1000: + break + print(webPath, timeGap, 'retry') + return getCurrentMillisecTime() def main(): basepath = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -37,29 +54,37 @@ def main(): resetAbsPath = servPath + '/j_autoreset.php' resetPath = webBase + '/' + servRelPath + '/j_autoreset.php' if os.path.exists(resetAbsPath): - autoResetList.append(resetPath) + autoResetList.append((servRelPath, resetPath)) if servPath in hiddenList: continue webPath = webBase + '/' + servRelPath + '/proc.php' - servList.append(webPath) + servList.append((servRelPath,webPath)) with concurrent.futures.ThreadPoolExecutor(max_workers=max(1,len(servList))) as executor: - waiters=[] - for resetPath in autoResetList: + waiters={} + startTime = getCurrentMillisecTime() + + waitTick = 1.0 / max(len(autoResetList), 1) + for servRelPath, resetPath in autoResetList: future = executor.submit(run, resetPath) - waiters.append(future) - for idx in range(10): - for webPath in servList: - future = executor.submit(run, webPath) - waiters.append(future) - if idx == 9: - break - time.sleep(6) - for future in waiters: - future.done() + waiters[servRelPath] = future + time.sleep(waitTick) + + currTime = getCurrentMillisecTime() + + waitTick = ONE_LOOP_TIME_SEC / max(len(servList), 1) + while currTime - startTime < ONE_FILE_LOOP_SEC*1000: + for servRelPath, webPath in servList: + if servRelPath in waiters and not waiters[servRelPath].done(): + continue + waiters[servRelPath] = executor.submit(run, webPath) + time.sleep(waitTick) + + for future in waiters.values(): + future.result(None) if __name__ == "__main__": # execute only if run as a script