1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-26 12:23:06 +08:00

Merge branch 'koogua/v1.6.1' of gitee.com:koogua/course-tencent-cloud into koogua/v1.6.1

This commit is contained in:
koogua 2022-12-12 15:58:33 +08:00
commit 77228b99f0
4 changed files with 38 additions and 29 deletions

View File

@ -60,7 +60,6 @@ class DeliverTask extends Task
break;
default:
$this->noMatchedHandler($order);
break;
}
$order->status = OrderModel::STATUS_FINISHED;

View File

@ -10,7 +10,7 @@ namespace App\Console\Tasks;
use App\Library\Benchmark;
use App\Models\User as UserModel;
use App\Services\Logic\Notice\External\DingTalk\ServerMonitor as ServerMonitorNotice;
use App\Services\Search\UserSearcher;
use App\Services\Search\CourseSearcher;
use GatewayClient\Gateway;
class ServerMonitorTask extends Task
@ -56,6 +56,8 @@ class ServerMonitorTask extends Task
if ($load[1] > $cpuCount * 0.8) {
return sprintf("cpu负载超过%s", $load[1]);
}
return null;
}
protected function checkMemory()
@ -64,25 +66,27 @@ class ServerMonitorTask extends Task
$total = null;
if (preg_match('/MemTotal\:\s+(\d+) kB/', $memInfo, $totalMatches)) {
if (preg_match('/MemTotal:\s+(\d+) kB/', $memInfo, $totalMatches)) {
$total = $totalMatches[1];
}
if ($total === null) return;
if ($total === null) return null;
$available = null;
if (preg_match('/MemAvailable\:\s+(\d+) kB/', $memInfo, $avaMatches)) {
if (preg_match('/MemAvailable:\s+(\d+) kB/', $memInfo, $avaMatches)) {
$available = $avaMatches[1];
}
if ($available === null) return;
if ($available === null) return null;
$left = 100 * ($available / $total);
if ($left < 20) {
return sprintf("memory剩余不足%s%%", round($left));
}
return null;
}
protected function checkDisk()
@ -95,6 +99,8 @@ class ServerMonitorTask extends Task
if ($left < 20) {
return sprintf("disk剩余不足%s%%", round($left));
}
return null;
}
protected function checkMysql()
@ -111,8 +117,8 @@ class ServerMonitorTask extends Task
$elapsedTime = $benchmark->getElapsedTime();
if ($user === false) {
return sprintf("mysql查询失败");
if (!$user) {
return "mysql查询失败";
}
if ($elapsedTime > 1) {
@ -120,8 +126,10 @@ class ServerMonitorTask extends Task
}
} catch (\Exception $e) {
return sprintf("mysql可能存在异常");
return "mysql可能存在异常";
}
return null;
}
protected function checkRedis()
@ -139,7 +147,7 @@ class ServerMonitorTask extends Task
$elapsedTime = $benchmark->getElapsedTime();
if (empty($site)) {
return sprintf("redis查询失败");
return "redis查询失败";
}
if ($elapsedTime > 1) {
@ -147,8 +155,10 @@ class ServerMonitorTask extends Task
}
} catch (\Exception $e) {
return sprintf("redis可能存在异常");
return "redis可能存在异常";
}
return null;
}
protected function checkXunsearch()
@ -159,16 +169,16 @@ class ServerMonitorTask extends Task
$benchmark->start();
$searcher = new UserSearcher();
$searcher = new CourseSearcher();
$user = $searcher->search('id:10000');
$user = $searcher->search('id:1');
$benchmark->stop();
$elapsedTime = $benchmark->getElapsedTime();
if (empty($user)) {
return sprintf("xunsearch搜索失败");
return "xunsearch搜索失败";
}
if ($elapsedTime > 1) {
@ -176,8 +186,10 @@ class ServerMonitorTask extends Task
}
} catch (\Exception $e) {
return sprintf("xunsearch可能存在异常");
return "xunsearch可能存在异常";
}
return null;
}
protected function checkWebsocket()
@ -203,8 +215,10 @@ class ServerMonitorTask extends Task
}
} catch (\Exception $e) {
return sprintf("websocket可能存在异常");
return "websocket可能存在异常";
}
return null;
}
protected function getCpuCount()

View File

@ -31,13 +31,13 @@ class ServerInfo
$total = 0;
if (preg_match('/MemTotal\:\s+(\d+) kB/', $mem, $totalMatches)) {
if (preg_match('/MemTotal:\s+(\d+) kB/', $mem, $totalMatches)) {
$total = $totalMatches[1];
}
$free = 0;
if (preg_match('/MemFree\:\s+(\d+) kB/', $mem, $freeMatches)) {
if (preg_match('/MemFree:\s+(\d+) kB/', $mem, $freeMatches)) {
$free = $freeMatches[1];
}

View File

@ -172,29 +172,25 @@ class Vod extends Service
$expiredTime = base_convert(time() + $expiry, 10, 16);
$tryTime = 0; // 试看时间0不限制
$ipLimit = 0; // ip数量限制0不限制
$random = rand(100000, 999999); // 随机数
$ipLimit = 9; // ip数量限制0不限制
$random = uniqid(); // 随机数
/**
* 腾讯坑爹的参数类型和文档,先凑合吧
* 不限制试看 => 必须exper=0(不能设置为空)
* 不限制IP => 必须rlimit为空不能设置为0,暂不可用
* 不限制IP => 必须rlimit为空不能设置为0
*/
$myTryTime = $tryTime >= 0 ? $tryTime : 0;
$myIpLimit = $ipLimit > 0 ? $ipLimit : '';
$myTryTime = $tryTime;
$myIpLimit = $ipLimit;
$sign = $key . $dirName . $expiredTime . $myTryTime . $myIpLimit . $random;
$query = [];
$query['t'] = $expiredTime;
if ($tryTime >= 0) {
$query['exper'] = $tryTime;
}
$query['exper'] = $myTryTime;
if ($ipLimit > 0) {
$query['rlimit'] = $ipLimit;
}
$query['rlimit'] = $myIpLimit;
$query['us'] = $random;