cleanp add delay option

This commit is contained in:
xiaomlove
2023-05-06 02:06:13 +08:00
parent 28b54ce053
commit a75abb91dc
3 changed files with 27 additions and 18 deletions
+7 -6
View File
@@ -14,14 +14,14 @@ class Cleanup extends Command
* *
* @var string * @var string
*/ */
protected $signature = 'cleanup {--action=} {--begin_id=} {--end_id=} {--request_id=}'; protected $signature = 'cleanup {--action=} {--begin_id=} {--end_id=} {--request_id=} {--delay=}';
/** /**
* The console command description. * The console command description.
* *
* @var string * @var string
*/ */
protected $description = 'Cleanup async job trigger, options: --begin_id, --end_id, --request_id, --action (seed_bonus, seeding_leeching_time, seeders_etc)'; protected $description = 'Cleanup async job trigger, options: --begin_id, --end_id, --request_id, --delay, --action (seed_bonus, seeding_leeching_time, seeders_etc)';
/** /**
* Execute the console command. * Execute the console command.
@@ -34,13 +34,14 @@ class Cleanup extends Command
$beginId = $this->option('begin_id'); $beginId = $this->option('begin_id');
$endId = $this->option('end_id'); $endId = $this->option('end_id');
$commentRequestId = $this->option('request_id'); $commentRequestId = $this->option('request_id');
$this->info("beginId: $beginId, endId: $endId, commentRequestId: $commentRequestId, action: $action"); $delay = $this->option('delay') ?: 0;
$this->info("beginId: $beginId, endId: $endId, commentRequestId: $commentRequestId, delay: $delay, action: $action");
if ($action == 'seed_bonus') { if ($action == 'seed_bonus') {
CalculateUserSeedBonus::dispatch($beginId, $endId, $commentRequestId); CalculateUserSeedBonus::dispatch($beginId, $endId, $commentRequestId)->delay($delay);
} elseif ($action == 'seeding_leeching_time') { } elseif ($action == 'seeding_leeching_time') {
UpdateUserSeedingLeechingTime::dispatch($beginId, $endId, $commentRequestId); UpdateUserSeedingLeechingTime::dispatch($beginId, $endId, $commentRequestId)->delay($delay);
}elseif ($action == 'seeders_etc') { }elseif ($action == 'seeders_etc') {
UpdateTorrentSeedersEtc::dispatch($beginId, $endId, $commentRequestId); UpdateTorrentSeedersEtc::dispatch($beginId, $endId, $commentRequestId)->delay($delay);
} else { } else {
$msg = "[$commentRequestId], Invalid action: $action"; $msg = "[$commentRequestId], Invalid action: $action";
do_log($msg, 'error'); do_log($msg, 'error');
+19 -11
View File
@@ -300,19 +300,22 @@ function docleanup($forceAll = 0, $printProgress = false) {
// } // }
//chunk async //chunk async
$asyncTaskCount = 3;
$baseDuration = floor($autoclean_interval_one / ($asyncTaskCount + 1));
$delayBase = 0;
$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'];
$chunk = 1000; $chunk = 1000;
$beginUid = 0; $beginUid = 0;
$chunkCounts = ceil($maxUid / $chunk); $chunkCounts = ceil($maxUid / $chunk);
$delay = ceil(600/$chunkCounts); $delay = ceil($baseDuration/$chunkCounts);
$i = 0; $i = 0;
do_log("maxUid: $maxUid, chunk: $chunk, chunkCounts: $chunkCounts"); do_log("autoclean_interval_one: $autoclean_interval_one, baseDuration: $baseDuration, maxUid: $maxUid, chunk: $chunk, chunkCounts: $chunkCounts, delayBase: $delayBase, delay: $delay");
do { do {
$command = sprintf( $command = sprintf(
'cleanup --action=seed_bonus --begin_id=%s --end_id=%s --request_id=%s --delay=%s', 'cleanup --action=seed_bonus --begin_id=%s --end_id=%s --request_id=%s --delay=%s',
$beginUid, $beginUid + $chunk, $requestId, $i * $delay $beginUid, $beginUid + $chunk, $requestId, $delayBase + $i * $delay
); );
$output = executeCommand($command, 'string', true); $output = executeCommand($command, 'string', true);
do_log(sprintf('command: %s, output: %s', $command, $output)); do_log(sprintf('command: %s, output: %s', $command, $output));
@@ -405,15 +408,15 @@ function docleanup($forceAll = 0, $printProgress = false) {
// sql_query("UPDATE torrents SET " . implode(",", $update) . " WHERE id = $id") or sqlerr(__FILE__, __LINE__); // sql_query("UPDATE torrents SET " . implode(",", $update) . " WHERE id = $id") or sqlerr(__FILE__, __LINE__);
// } // }
$delayBase = $baseDuration;
$maxTorrentIdRes = mysql_fetch_assoc(sql_query("select max(id) as max_torrent_id from torrents limit 1")); $maxTorrentIdRes = mysql_fetch_assoc(sql_query("select max(id) as max_torrent_id from torrents limit 1"));
$maxTorrentId = $maxTorrentIdRes['max_torrent_id']; $maxTorrentId = $maxTorrentIdRes['max_torrent_id'];
$chunk = 1000; $chunk = 1000;
$beginTorrentId = 0; $beginTorrentId = 0;
$chunkCounts = ceil($maxTorrentId / $chunk); $chunkCounts = ceil($maxTorrentId / $chunk);
$delayBase = 600; $delay = ceil($baseDuration/$chunkCounts);
$delay = ceil(600/$chunkCounts);
$i = 0; $i = 0;
do_log("maxUid: $maxUid, chunk: $chunk, chunkCounts: $chunkCounts"); do_log("maxTorrentId: $maxTorrentId, chunk: $chunk, chunkCounts: $chunkCounts, delayBase: $delayBase, delay: $delay");
do { do {
$command = sprintf( $command = sprintf(
'cleanup --action=seeders_etc --begin_id=%s --end_id=%s --request_id=%s --delay=%s', 'cleanup --action=seeders_etc --begin_id=%s --end_id=%s --request_id=%s --delay=%s',
@@ -913,15 +916,20 @@ function docleanup($forceAll = 0, $printProgress = false) {
$chunk = 1000; $chunk = 1000;
$beginUid = 0; $beginUid = 0;
do_log("maxUid: $maxUid, chunk: $chunk"); $delayBase = $baseDuration * 2;
$chunkCounts = ceil($maxUid / $chunk);
$delay = ceil($baseDuration/$chunkCounts);
$i = 0;
do_log("maxUid: $maxUid, chunk: $chunk, chunkCounts: $chunkCounts, delayBase: $delayBase, delay: $delay");
do { do {
$command = sprintf( $command = sprintf(
'%s %s/artisan cleanup --action=seeding_leeching_time --begin_id=%s --end_id=%s --request_id=%s', 'cleanup --action=seeding_leeching_time --begin_id=%s --end_id=%s --request_id=%s --delay=%s',
$phpPath, $webRoot, $beginUid, $beginUid + $chunk, $requestId $beginUid, $beginUid + $chunk, $requestId, $delayBase + $delay * $i
); );
$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 = "update total seeding and leeching time of users"; $log = "update total seeding and leeching time of users";
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.2'); defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.2');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-04-30'); defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-05-06');
defined('IN_TRACKER') || define('IN_TRACKER', false); defined('IN_TRACKER') || define('IN_TRACKER', false);
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP"); defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org"); defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");