cleanup delay

This commit is contained in:
xiaomlove
2023-05-03 23:59:30 +08:00
parent 1a22fd6584
commit 28b54ce053
3 changed files with 28 additions and 21 deletions
+1 -2
View File
@@ -97,8 +97,7 @@ class Test extends Command
*/ */
public function handle() public function handle()
{ {
$rep = new ExamRepository(); $r = number_format(12356);
$r = $rep->listMatchExam(1);
dd($r); dd($r);
} }
+19 -12
View File
@@ -303,19 +303,21 @@ function docleanup($forceAll = 0, $printProgress = false) {
$requestId = nexus()->getRequestId(); $requestId = nexus()->getRequestId();
$maxUidRes = mysql_fetch_assoc(sql_query("select max(id) as max_uid from users limit 1")); $maxUidRes = mysql_fetch_assoc(sql_query("select max(id) as max_uid from users limit 1"));
$maxUid = $maxUidRes['max_uid']; $maxUid = $maxUidRes['max_uid'];
$phpPath = nexus_env('PHP_PATH') ?: 'php';
$webRoot = rtrim(ROOT_PATH, '/');
$chunk = 1000; $chunk = 1000;
$beginUid = 0; $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 { do {
$command = sprintf( $command = sprintf(
'%s %s/artisan cleanup --action=seed_bonus --begin_id=%s --end_id=%s --request_id=%s', 'cleanup --action=seed_bonus --begin_id=%s --end_id=%s --request_id=%s --delay=%s',
$phpPath, $webRoot, $beginUid, $beginUid + $chunk, $requestId $beginUid, $beginUid + $chunk, $requestId, $i * $delay
); );
$result = exec("$command 2>&1", $output, $result_code); $output = executeCommand($command, 'string', true);
do_log(sprintf('command: %s, result_code: %s, result: %s, output: %s', $command, $result_code, $result, json_encode($output))); do_log(sprintf('command: %s, output: %s', $command, $output));
$beginUid += $chunk; $beginUid += $chunk;
$i++;
} while ($beginUid < $maxUid); } while ($beginUid < $maxUid);
$log = 'calculate seeding bonus'; $log = 'calculate seeding bonus';
@@ -407,15 +409,20 @@ function docleanup($forceAll = 0, $printProgress = false) {
$maxTorrentId = $maxTorrentIdRes['max_torrent_id']; $maxTorrentId = $maxTorrentIdRes['max_torrent_id'];
$chunk = 1000; $chunk = 1000;
$beginTorrentId = 0; $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 { do {
$command = sprintf( $command = sprintf(
'%s %s/artisan cleanup --action=seeders_etc --begin_id=%s --end_id=%s --request_id=%s', 'cleanup --action=seeders_etc --begin_id=%s --end_id=%s --request_id=%s --delay=%s',
$phpPath, $webRoot, $beginTorrentId, $beginTorrentId + $chunk, $requestId $beginTorrentId, $beginTorrentId + $chunk, $requestId, $delayBase + $i * $delay
); );
$result = exec("$command 2>&1", $output, $result_code); $output = executeCommand($command, 'string', true);
do_log(sprintf('command: %s, result_code: %s, result: %s, output: %s', $command, $result_code, $result, json_encode($output))); do_log(sprintf('command: %s, output: %s', $command, $output));
$beginTorrentId += $chunk; $beginTorrentId += $chunk;
$i++;
} while ($beginTorrentId < $maxTorrentId); } while ($beginTorrentId < $maxTorrentId);
$log = "update count of seeders, leechers, comments for torrents"; $log = "update count of seeders, leechers, comments for torrents";
do_log($log); do_log($log);
+8 -7
View File
@@ -641,13 +641,14 @@ class Install
public function executeCommand($command) public function executeCommand($command)
{ {
$this->doLog("command: $command"); executeCommand($command);
$result = exec($command, $output, $result_code); // $this->doLog("command: $command");
$this->doLog(sprintf('result_code: %s, result: %s', $result_code, $result)); // $result = exec($command, $output, $result_code);
$this->doLog("output: " . json_encode($output)); // $this->doLog(sprintf('result_code: %s, result: %s', $result_code, $result));
if ($result_code != 0) { // $this->doLog("output: " . json_encode($output));
throw new \RuntimeException(json_encode($output)); // if ($result_code != 0) {
} // throw new \RuntimeException(json_encode($output));
// }
} }
public function runDatabaseSeeder() public function runDatabaseSeeder()