cleanup job add idRedisKey

This commit is contained in:
lgb
2024-02-21 21:11:16 +08:00
parent 9fe932e244
commit cbfae32d30
5 changed files with 70 additions and 24 deletions
+22 -12
View File
@@ -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");
}
+18 -2
View File
@@ -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",
+18 -2
View File
@@ -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");
}