mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-19 16:20:50 +08:00
cleanp add delay option
This commit is contained in:
@@ -14,14 +14,14 @@ class Cleanup extends Command
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* @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.
|
||||
@@ -34,13 +34,14 @@ class Cleanup extends Command
|
||||
$beginId = $this->option('begin_id');
|
||||
$endId = $this->option('end_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') {
|
||||
CalculateUserSeedBonus::dispatch($beginId, $endId, $commentRequestId);
|
||||
CalculateUserSeedBonus::dispatch($beginId, $endId, $commentRequestId)->delay($delay);
|
||||
} elseif ($action == 'seeding_leeching_time') {
|
||||
UpdateUserSeedingLeechingTime::dispatch($beginId, $endId, $commentRequestId);
|
||||
UpdateUserSeedingLeechingTime::dispatch($beginId, $endId, $commentRequestId)->delay($delay);
|
||||
}elseif ($action == 'seeders_etc') {
|
||||
UpdateTorrentSeedersEtc::dispatch($beginId, $endId, $commentRequestId);
|
||||
UpdateTorrentSeedersEtc::dispatch($beginId, $endId, $commentRequestId)->delay($delay);
|
||||
} else {
|
||||
$msg = "[$commentRequestId], Invalid action: $action";
|
||||
do_log($msg, 'error');
|
||||
|
||||
@@ -300,19 +300,22 @@ function docleanup($forceAll = 0, $printProgress = false) {
|
||||
// }
|
||||
|
||||
//chunk async
|
||||
$asyncTaskCount = 3;
|
||||
$baseDuration = floor($autoclean_interval_one / ($asyncTaskCount + 1));
|
||||
$delayBase = 0;
|
||||
$requestId = nexus()->getRequestId();
|
||||
$maxUidRes = mysql_fetch_assoc(sql_query("select max(id) as max_uid from users limit 1"));
|
||||
$maxUid = $maxUidRes['max_uid'];
|
||||
$chunk = 1000;
|
||||
$beginUid = 0;
|
||||
$chunkCounts = ceil($maxUid / $chunk);
|
||||
$delay = ceil(600/$chunkCounts);
|
||||
$delay = ceil($baseDuration/$chunkCounts);
|
||||
$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 {
|
||||
$command = sprintf(
|
||||
'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);
|
||||
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__);
|
||||
// }
|
||||
|
||||
$delayBase = $baseDuration;
|
||||
$maxTorrentIdRes = mysql_fetch_assoc(sql_query("select max(id) as max_torrent_id from torrents limit 1"));
|
||||
$maxTorrentId = $maxTorrentIdRes['max_torrent_id'];
|
||||
$chunk = 1000;
|
||||
$beginTorrentId = 0;
|
||||
$chunkCounts = ceil($maxTorrentId / $chunk);
|
||||
$delayBase = 600;
|
||||
$delay = ceil(600/$chunkCounts);
|
||||
$delay = ceil($baseDuration/$chunkCounts);
|
||||
$i = 0;
|
||||
do_log("maxUid: $maxUid, chunk: $chunk, chunkCounts: $chunkCounts");
|
||||
do_log("maxTorrentId: $maxTorrentId, chunk: $chunk, chunkCounts: $chunkCounts, delayBase: $delayBase, delay: $delay");
|
||||
do {
|
||||
$command = sprintf(
|
||||
'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;
|
||||
$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 {
|
||||
$command = sprintf(
|
||||
'%s %s/artisan cleanup --action=seeding_leeching_time --begin_id=%s --end_id=%s --request_id=%s',
|
||||
$phpPath, $webRoot, $beginUid, $beginUid + $chunk, $requestId
|
||||
'cleanup --action=seeding_leeching_time --begin_id=%s --end_id=%s --request_id=%s --delay=%s',
|
||||
$beginUid, $beginUid + $chunk, $requestId, $delayBase + $delay * $i
|
||||
);
|
||||
$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 = "update total seeding and leeching time of users";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
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('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
|
||||
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
||||
|
||||
Reference in New Issue
Block a user