From 28b54ce05379226a6d0411360a4ebc9d5a6fa518 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Wed, 3 May 2023 23:59:30 +0800 Subject: [PATCH] cleanup delay --- app/Console/Commands/Test.php | 3 +-- include/cleanup.php | 31 +++++++++++++++++++------------ nexus/Install/Install.php | 15 ++++++++------- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/app/Console/Commands/Test.php b/app/Console/Commands/Test.php index f12530d6..8503fc34 100644 --- a/app/Console/Commands/Test.php +++ b/app/Console/Commands/Test.php @@ -97,8 +97,7 @@ class Test extends Command */ public function handle() { - $rep = new ExamRepository(); - $r = $rep->listMatchExam(1); + $r = number_format(12356); dd($r); } diff --git a/include/cleanup.php b/include/cleanup.php index 2bc11291..bcfa463d 100644 --- a/include/cleanup.php +++ b/include/cleanup.php @@ -303,19 +303,21 @@ function docleanup($forceAll = 0, $printProgress = false) { $requestId = nexus()->getRequestId(); $maxUidRes = mysql_fetch_assoc(sql_query("select max(id) as max_uid from users limit 1")); $maxUid = $maxUidRes['max_uid']; - $phpPath = nexus_env('PHP_PATH') ?: 'php'; - $webRoot = rtrim(ROOT_PATH, '/'); $chunk = 1000; $beginUid = 0; - do_log("maxUid: $maxUid, chunk: $chunk"); + $chunkCounts = ceil($maxUid / $chunk); + $delay = ceil(600/$chunkCounts); + $i = 0; + do_log("maxUid: $maxUid, chunk: $chunk, chunkCounts: $chunkCounts"); do { $command = sprintf( - '%s %s/artisan cleanup --action=seed_bonus --begin_id=%s --end_id=%s --request_id=%s', - $phpPath, $webRoot, $beginUid, $beginUid + $chunk, $requestId + 'cleanup --action=seed_bonus --begin_id=%s --end_id=%s --request_id=%s --delay=%s', + $beginUid, $beginUid + $chunk, $requestId, $i * $delay ); - $result = exec("$command 2>&1", $output, $result_code); - do_log(sprintf('command: %s, result_code: %s, result: %s, output: %s', $command, $result_code, $result, json_encode($output))); + $output = executeCommand($command, 'string', true); + do_log(sprintf('command: %s, output: %s', $command, $output)); $beginUid += $chunk; + $i++; } while ($beginUid < $maxUid); $log = 'calculate seeding bonus'; @@ -407,15 +409,20 @@ function docleanup($forceAll = 0, $printProgress = false) { $maxTorrentId = $maxTorrentIdRes['max_torrent_id']; $chunk = 1000; $beginTorrentId = 0; - do_log("maxTorrentId: $maxTorrentId, chunk: $chunk"); + $chunkCounts = ceil($maxTorrentId / $chunk); + $delayBase = 600; + $delay = ceil(600/$chunkCounts); + $i = 0; + do_log("maxUid: $maxUid, chunk: $chunk, chunkCounts: $chunkCounts"); do { $command = sprintf( - '%s %s/artisan cleanup --action=seeders_etc --begin_id=%s --end_id=%s --request_id=%s', - $phpPath, $webRoot, $beginTorrentId, $beginTorrentId + $chunk, $requestId + 'cleanup --action=seeders_etc --begin_id=%s --end_id=%s --request_id=%s --delay=%s', + $beginTorrentId, $beginTorrentId + $chunk, $requestId, $delayBase + $i * $delay ); - $result = exec("$command 2>&1", $output, $result_code); - do_log(sprintf('command: %s, result_code: %s, result: %s, output: %s', $command, $result_code, $result, json_encode($output))); + $output = executeCommand($command, 'string', true); + do_log(sprintf('command: %s, output: %s', $command, $output)); $beginTorrentId += $chunk; + $i++; } while ($beginTorrentId < $maxTorrentId); $log = "update count of seeders, leechers, comments for torrents"; do_log($log); diff --git a/nexus/Install/Install.php b/nexus/Install/Install.php index d2828849..d1d344bb 100644 --- a/nexus/Install/Install.php +++ b/nexus/Install/Install.php @@ -641,13 +641,14 @@ class Install public function executeCommand($command) { - $this->doLog("command: $command"); - $result = exec($command, $output, $result_code); - $this->doLog(sprintf('result_code: %s, result: %s', $result_code, $result)); - $this->doLog("output: " . json_encode($output)); - if ($result_code != 0) { - throw new \RuntimeException(json_encode($output)); - } + executeCommand($command); +// $this->doLog("command: $command"); +// $result = exec($command, $output, $result_code); +// $this->doLog(sprintf('result_code: %s, result: %s', $result_code, $result)); +// $this->doLog("output: " . json_encode($output)); +// if ($result_code != 0) { +// throw new \RuntimeException(json_encode($output)); +// } } public function runDatabaseSeeder()