mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 12:30:49 +08:00
cleanup job add idRedisKey
This commit is contained in:
@@ -14,14 +14,14 @@ class Cleanup extends Command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'cleanup {--action=} {--begin_id=} {--id_str=} {--end_id=} {--request_id=} {--delay=}';
|
||||
protected $signature = 'cleanup {--action=} {--begin_id=} {--id_str=} {--end_id=} {--request_id=} {--delay=} {--id_redis_key}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Cleanup async job trigger, options: --begin_id, --end_id, --id_str, --request_id, --delay, --action (seed_bonus, seeding_leeching_time, seeders_etc)';
|
||||
protected $description = 'Cleanup async job trigger, options: --begin_id, --end_id, --id_str, --request_id, --delay, --id_redis_key,--action (seed_bonus, seeding_leeching_time, seeders_etc)';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
@@ -34,15 +34,16 @@ class Cleanup extends Command
|
||||
$beginId = $this->option('begin_id');
|
||||
$endId = $this->option('end_id');
|
||||
$idStr = $this->option('id_str') ?: "";
|
||||
$idRedisKey = $this->option('id_redis_key') ?: "";
|
||||
$commentRequestId = $this->option('request_id');
|
||||
$delay = $this->option('delay') ?: 0;
|
||||
$this->info("beginId: $beginId, endId: $endId, idStr: $idStr, commentRequestId: $commentRequestId, delay: $delay, action: $action");
|
||||
$this->info("beginId: $beginId, endId: $endId, idStr: $idStr, idRedisKey: $idRedisKey, commentRequestId: $commentRequestId, delay: $delay, action: $action");
|
||||
if ($action == 'seed_bonus') {
|
||||
CalculateUserSeedBonus::dispatch($beginId, $endId, $idStr, $commentRequestId)->delay($delay);
|
||||
CalculateUserSeedBonus::dispatch($beginId, $endId, $idStr, $idRedisKey, $commentRequestId)->delay($delay);
|
||||
} elseif ($action == 'seeding_leeching_time') {
|
||||
UpdateUserSeedingLeechingTime::dispatch($beginId, $endId, $idStr, $commentRequestId)->delay($delay);
|
||||
UpdateUserSeedingLeechingTime::dispatch($beginId, $endId, $idStr, $idRedisKey, $commentRequestId)->delay($delay);
|
||||
}elseif ($action == 'seeders_etc') {
|
||||
UpdateTorrentSeedersEtc::dispatch($beginId, $endId, $idStr, $commentRequestId)->delay($delay);
|
||||
UpdateTorrentSeedersEtc::dispatch($beginId, $endId, $idStr, $idRedisKey, $commentRequestId)->delay($delay);
|
||||
} else {
|
||||
$msg = "[$commentRequestId], Invalid action: $action";
|
||||
do_log($msg, 'error');
|
||||
|
||||
@@ -11,6 +11,7 @@ use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Nexus\Database\NexusDB;
|
||||
use Nexus\Nexus;
|
||||
|
||||
class CalculateUserSeedBonus implements ShouldQueue
|
||||
{
|
||||
@@ -20,20 +21,23 @@ class CalculateUserSeedBonus implements ShouldQueue
|
||||
|
||||
private int $endUid;
|
||||
|
||||
private string $uidArrStr;
|
||||
private string $idStr;
|
||||
|
||||
private string $requestId;
|
||||
|
||||
private string $idRedisKey;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(int $beginUid, int $endUid, string $uidArrStr, string $requestId = '')
|
||||
public function __construct(int $beginUid, int $endUid, string $idStr, string $idRedisKey, string $requestId = '')
|
||||
{
|
||||
$this->beginUid = $beginUid;
|
||||
$this->endUid = $endUid;
|
||||
$this->uidArrStr = $uidArrStr;
|
||||
$this->idStr = $idStr;
|
||||
$this->idRedisKey = $idRedisKey;
|
||||
$this->requestId = $requestId;
|
||||
}
|
||||
|
||||
@@ -60,19 +64,22 @@ class CalculateUserSeedBonus implements ShouldQueue
|
||||
{
|
||||
$beginTimestamp = time();
|
||||
$logPrefix = sprintf("[CLEANUP_CLI_CALCULATE_SEED_BONUS_HANDLE_JOB], commonRequestId: %s, beginUid: %s, endUid: %s", $this->requestId, $this->beginUid, $this->endUid);
|
||||
// $sql = sprintf("select userid from peers where userid > %s and userid <= %s and seeder = 'yes' group by userid", $this->beginUid, $this->endUid);
|
||||
// $results = NexusDB::select($sql);
|
||||
// $count = count($results);
|
||||
// do_log("$logPrefix, [GET_UID], sql: $sql, count: " . count($results));
|
||||
// if ($count == 0) {
|
||||
// do_log("$logPrefix, no user...");
|
||||
// return;
|
||||
// }
|
||||
$haremAdditionFactor = Setting::get('bonus.harem_addition');
|
||||
$officialAdditionFactor = Setting::get('bonus.official_addition');
|
||||
$donortimes_bonus = Setting::get('bonus.donortimes');
|
||||
$autoclean_interval_one = Setting::get('main.autoclean_interval_one');
|
||||
$sql = sprintf("select %s from users where id in (%s)", implode(',', User::$commonFields), $this->uidArrStr);
|
||||
|
||||
$idStr = $this->idStr;
|
||||
$delIdRedisKey = false;
|
||||
if (empty($idStr) && !empty($this->idRedisKey)) {
|
||||
$delIdRedisKey = true;
|
||||
$idStr = NexusDB::cache_get($this->idRedisKey);
|
||||
}
|
||||
if (empty($idStr)) {
|
||||
do_log("$logPrefix, no idStr or idRedisKey", "error");
|
||||
return;
|
||||
}
|
||||
$sql = sprintf("select %s from users where id in (%s)", implode(',', User::$commonFields), $idStr);
|
||||
$results = NexusDB::select($sql);
|
||||
$logFile = getLogFile("seed-bonus-points");
|
||||
do_log("$logPrefix, [GET_UID_REAL], count: " . count($results) . ", logFile: $logFile");
|
||||
@@ -124,6 +131,9 @@ class CalculateUserSeedBonus implements ShouldQueue
|
||||
do_log("logFile: $logFile is not writeable!", 'error');
|
||||
}
|
||||
}
|
||||
if ($delIdRedisKey) {
|
||||
NexusDB::cache_del($this->idRedisKey);
|
||||
}
|
||||
$costTime = time() - $beginTimestamp;
|
||||
do_log("$logPrefix, [DONE], cost time: $costTime seconds");
|
||||
}
|
||||
|
||||
@@ -25,16 +25,19 @@ class UpdateTorrentSeedersEtc implements ShouldQueue
|
||||
|
||||
private ?string $idStr = null;
|
||||
|
||||
private string $idRedisKey;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(int $beginTorrentId, int $endTorrentId, string $idStr, string $requestId = '')
|
||||
public function __construct(int $beginTorrentId, int $endTorrentId, string $idStr, string $idRedisKey, string $requestId = '')
|
||||
{
|
||||
$this->beginTorrentId = $beginTorrentId;
|
||||
$this->endTorrentId = $endTorrentId;
|
||||
$this->idStr = $idStr;
|
||||
$this->idRedisKey = $idRedisKey;
|
||||
$this->requestId = $requestId;
|
||||
}
|
||||
|
||||
@@ -62,7 +65,17 @@ class UpdateTorrentSeedersEtc implements ShouldQueue
|
||||
$beginTimestamp = time();
|
||||
$logPrefix = sprintf("[CLEANUP_CLI_UPDATE_TORRENT_SEEDERS_ETC_HANDLE_JOB], commonRequestId: %s, beginTorrentId: %s, endTorrentId: %s", $this->requestId, $this->beginTorrentId, $this->endTorrentId);
|
||||
|
||||
$torrentIdArr = explode(",", $this->idStr);
|
||||
$idStr = $this->idStr;
|
||||
$delIdRedisKey = false;
|
||||
if (empty($idStr) && !empty($this->idRedisKey)) {
|
||||
$delIdRedisKey = true;
|
||||
$idStr = NexusDB::cache_get($this->idRedisKey);
|
||||
}
|
||||
if (empty($idStr)) {
|
||||
do_log("$logPrefix, no idStr or idRedisKey", "error");
|
||||
return;
|
||||
}
|
||||
$torrentIdArr = explode(",", $idStr);
|
||||
foreach ($torrentIdArr as $torrentId) {
|
||||
if ($torrentId <= 0) {
|
||||
continue;
|
||||
@@ -93,6 +106,9 @@ class UpdateTorrentSeedersEtc implements ShouldQueue
|
||||
NexusDB::table('torrents')->where('id', $torrentId)->update($update);
|
||||
do_log("[CLEANUP_CLI_UPDATE_TORRENT_SEEDERS_ETC_HANDLE_TORRENT], [SUCCESS]: $torrentId => " . json_encode($update));
|
||||
}
|
||||
if ($delIdRedisKey) {
|
||||
NexusDB::cache_del($this->idRedisKey);
|
||||
}
|
||||
$costTime = time() - $beginTimestamp;
|
||||
do_log(sprintf(
|
||||
"$logPrefix, [DONE], update torrent count: %s, cost time: %s seconds",
|
||||
|
||||
@@ -25,16 +25,19 @@ class UpdateUserSeedingLeechingTime implements ShouldQueue
|
||||
|
||||
private ?string $idStr = null;
|
||||
|
||||
private string $idRedisKey;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(int $beginUid, int $endUid, string $idStr, string $requestId = '')
|
||||
public function __construct(int $beginUid, int $endUid, string $idStr, string $idRedisKey, string $requestId = '')
|
||||
{
|
||||
$this->beginUid = $beginUid;
|
||||
$this->endUid = $endUid;
|
||||
$this->idStr = $idStr;
|
||||
$this->idRedisKey = $idRedisKey;
|
||||
$this->requestId = $requestId;
|
||||
}
|
||||
|
||||
@@ -63,7 +66,17 @@ class UpdateUserSeedingLeechingTime implements ShouldQueue
|
||||
$logPrefix = sprintf("[CLEANUP_CLI_UPDATE_SEEDING_LEECHING_TIME_HANDLE_JOB], commonRequestId: %s, beginUid: %s, endUid: %s", $this->requestId, $this->beginUid, $this->endUid);
|
||||
|
||||
$count = 0;
|
||||
$uidArr = explode(",", $this->idStr);
|
||||
$idStr = $this->idStr;
|
||||
$delIdRedisKey = false;
|
||||
if (empty($idStr) && !empty($this->idRedisKey)) {
|
||||
$delIdRedisKey = true;
|
||||
$idStr = NexusDB::cache_get($this->idRedisKey);
|
||||
}
|
||||
if (empty($idStr)) {
|
||||
do_log("$logPrefix, no idStr or idRedisKey", "error");
|
||||
return;
|
||||
}
|
||||
$uidArr = explode(",", $idStr);
|
||||
foreach ($uidArr as $uid) {
|
||||
if ($uid <= 0) {
|
||||
continue;
|
||||
@@ -85,6 +98,9 @@ class UpdateUserSeedingLeechingTime implements ShouldQueue
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
if ($delIdRedisKey) {
|
||||
NexusDB::cache_del($this->idRedisKey);
|
||||
}
|
||||
$costTime = time() - $beginTimestamp;
|
||||
do_log("$logPrefix, [DONE], user total count: " . count($uidArr) . ", success update count: $count, cost time: $costTime seconds");
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Repositories;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Str;
|
||||
use Nexus\Database\NexusDB;
|
||||
|
||||
class CleanupRepository extends BaseRepository
|
||||
@@ -95,9 +96,11 @@ class CleanupRepository extends BaseRepository
|
||||
while($arr_keys = $redis->hScan($batch, $it, "*", self::$scanSize)) {
|
||||
$delay = self::getDelay($batchKeyInfo['task_index'], $length, $page);
|
||||
$idStr = implode(",", array_keys($arr_keys));
|
||||
$idRedisKey = Str::random();
|
||||
NexusDB::cache_put($idRedisKey, $idStr);
|
||||
$command = sprintf(
|
||||
'cleanup --action=%s --begin_id=%s --end_id=%s --id_str=%s --request_id=%s --delay=%s',
|
||||
$batchKeyInfo['action'], 0, 0, $idStr, $requestId, $delay
|
||||
'cleanup --action=%s --begin_id=%s --end_id=%s --id_redis_key=%s --request_id=%s --delay=%s',
|
||||
$batchKeyInfo['action'], 0, 0, $idRedisKey, $requestId, $delay
|
||||
);
|
||||
$output = executeCommand($command, 'string', true);
|
||||
do_log(sprintf('output: %s', $output));
|
||||
|
||||
Reference in New Issue
Block a user