improve job log

This commit is contained in:
xiaomlove
2023-02-21 01:04:28 +08:00
parent 64defea3e3
commit eb04b9d2d0
7 changed files with 45 additions and 23 deletions

View File

@@ -95,9 +95,8 @@ class Test extends Command
*/
public function handle()
{
$now = Carbon::now();
$now->addSeconds();
dd($diffInSeconds);
$r = unserialize('{"command":"O:31:\"App\\Jobs\\CalculateUserSeedBonus\":3:{s:41:\"\u0000App\\Jobs\\CalculateUserSeedBonus\u0000beginUid\";i:32000;s:39:\"\u0000App\\Jobs\\CalculateUserSeedBonus\u0000endUid\";i:34000;s:42:\"\u0000App\\Jobs\\CalculateUserSeedBonus\u0000requestId\";s:32:\"2f6563f399f26f57b02882463199a49d\";}');
dd($r);
}
}

View File

@@ -52,7 +52,7 @@ class CalculateUserSeedBonus implements ShouldQueue
public function handle()
{
$beginTimestamp = time();
$logPrefix = sprintf("[CLEANUP_CLI_CALCULATE_SEED_BONUS], commonRequestId: %s, beginUid: %s, endUid: %s", $this->requestId, $this->beginUid, $this->endUid);
$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);
@@ -73,7 +73,7 @@ class CalculateUserSeedBonus implements ShouldQueue
$uid = $userInfo['id'];
$isDonor = is_donor($userInfo);
$seedBonusResult = calculate_seed_bonus($uid);
$bonusLog = "[CLEANUP_CALCULATE_SEED_BONUS], user: $uid, seedBonusResult: " . nexus_json_encode($seedBonusResult);
$bonusLog = "[CLEANUP_CLI_CALCULATE_SEED_BONUS_HANDLE_USER], user: $uid, seedBonusResult: " . nexus_json_encode($seedBonusResult);
$all_bonus = $seedBonusResult['seed_bonus'];
$bonusLog .= ", all_bonus: $all_bonus";
if ($isDonor) {
@@ -107,4 +107,15 @@ class CalculateUserSeedBonus implements ShouldQueue
$costTime = time() - $beginTimestamp;
do_log("$logPrefix, [DONE], cost time: $costTime seconds");
}
/**
* Handle a job failure.
*
* @param \Throwable $exception
* @return void
*/
public function failed(\Throwable $exception)
{
do_log("failed: " . $exception->getMessage() . $exception->getTraceAsString(), 'error');
}
}

View File

@@ -52,7 +52,7 @@ class UpdateTorrentSeedersEtc implements ShouldQueue
public function handle()
{
$beginTimestamp = time();
$logPrefix = sprintf("[CLEANUP_CLI_UPDATE_TORRENT_SEEDERS_ETC], commonRequestId: %s, beginTorrentId: %s, endTorrentId: %s", $this->requestId, $this->beginTorrentId, $this->endTorrentId);
$logPrefix = sprintf("[CLEANUP_CLI_UPDATE_TORRENT_SEEDERS_ETC_HANDLE_JOB], commonRequestId: %s, beginTorrentId: %s, endTorrentId: %s", $this->requestId, $this->beginTorrentId, $this->endTorrentId);
// $sql = sprintf("update torrents set seeders = (select count(*) from peers where torrent = torrents.id and seeder = 'yes'), leechers = (select count(*) from peers where torrent = torrents.id and seeder = 'no'), comments = (select count(*) from comments where torrent = torrents.id) where id > %s and id <= %s",
// $this->beginTorrentId, $this->endTorrentId
// );
@@ -88,7 +88,7 @@ class UpdateTorrentSeedersEtc implements ShouldQueue
}
}
NexusDB::table('torrents')->where('id', $torrent->id)->update($update);
do_log("$logPrefix, [SUCCESS]: $torrent->id => " . json_encode($update));
do_log("[CLEANUP_CLI_UPDATE_TORRENT_SEEDERS_ETC_HANDLE_TORRENT], [SUCCESS]: $torrent->id => " . json_encode($update));
}
$costTime = time() - $beginTimestamp;
do_log(sprintf(
@@ -96,4 +96,15 @@ class UpdateTorrentSeedersEtc implements ShouldQueue
count($torrents), $costTime
));
}
/**
* Handle a job failure.
*
* @param \Throwable $exception
* @return void
*/
public function failed(\Throwable $exception)
{
do_log("failed: " . $exception->getMessage() . $exception->getTraceAsString(), 'error');
}
}

View File

@@ -35,15 +35,17 @@ class ClaimRepository extends BaseRepository
if ($exists) {
throw new \RuntimeException(nexus_trans("torrent.claim_already"));
}
$max = Claim::getConfigTorrentUpLimit();
$count = Claim::query()->where('uid', $uid)->count();
if ($count >= $max) {
throw new \RuntimeException(nexus_trans("torrent.claim_number_reach_torrent_maximum"));
}
$max = Claim::getConfigUserUpLimit();
$count = Claim::query()->where('torrent_id', $torrentId)->count();
if ($count >= $max) {
throw new \RuntimeException(nexus_trans("torrent.claim_number_reach_user_maximum"));
if (!apply_filter('user_has_role_work_seeding', false, $uid)) {
$max = Claim::getConfigTorrentUpLimit();
$count = Claim::query()->where('uid', $uid)->count();
if ($count >= $max) {
throw new \RuntimeException(nexus_trans("torrent.claim_number_reach_torrent_maximum"));
}
$max = Claim::getConfigUserUpLimit();
$count = Claim::query()->where('torrent_id', $torrentId)->count();
if ($count >= $max) {
throw new \RuntimeException(nexus_trans("torrent.claim_number_reach_user_maximum"));
}
}
$snatch = Snatch::query()->where('userid', $uid)->where('torrentid', $torrentId)->first();
if (!$snatch) {
@@ -153,9 +155,9 @@ class ClaimRepository extends BaseRepository
public function settleUser($uid, $force = false, $test = false): bool
{
$shouldDoSettle = apply_filter('user_should_do_claim_settle', true, $uid);
if (!$shouldDoSettle) {
do_log("uid: $uid, filter: user_should_do_claim_settle => false");
$hasRoleWorkSeeding = apply_filter('user_has_role_work_seeding', false, $uid);
if ($hasRoleWorkSeeding) {
do_log("uid: $uid, filter: user_has_role_work_seeding => true, skip");
return false;
}
$user = User::query()->with('language')->findOrFail($uid);

View File

@@ -1,6 +1,6 @@
<?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.0');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-02-12');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-02-21');
defined('IN_TRACKER') || define('IN_TRACKER', false);
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");

View File

@@ -1,7 +1,7 @@
<?php
require '../include/bittorrent_announce.php';
require ROOT_PATH . 'include/core.php';
do_log(nexus_json_encode($_SERVER));
//do_log(nexus_json_encode($_SERVER));
//1. BLOCK ACCESS WITH WEB BROWSERS AND CHEATS!
$agent = $_SERVER["HTTP_USER_AGENT"] ?? '';
block_browser();
@@ -155,7 +155,7 @@ if ($torrent['approval_status'] != \App\Models\Torrent::APPROVAL_STATUS_ALLOW &&
if ($seeder == 'no' && isset($torrent['price']) && $torrent['price'] > 0 && $torrent['owner'] != $userid) {
$hasBuy = \App\Models\TorrentBuyLog::query()->where('uid', $userid)->where('torrent_id', $torrent['id'])->exists();
if (!$hasBuy) {
err("You have not buy the torrent yet");
err("You have not purchased this torrent yet");
}
}

View File

@@ -225,7 +225,6 @@ if (user_can('userprofile')) {
if ($iphistory > 0)
tr_small($lang_userdetails['row_ip_history'], $lang_userdetails['text_user_earlier_used']."<b><a href=\"iphistory.php?id=" . $user['id'] . "\">" . $iphistory. $lang_userdetails['text_different_ips'].add_s($iphistory, true)."</a></b>", 1);
}
$seedBoxRep = new \App\Repositories\SeedBoxRepository();
if (user_can('userprofile') || $user["id"] == $CURUSER["id"])