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

优化语法结构

This commit is contained in:
xiaochong0302 2022-11-28 19:28:07 +08:00
parent 46beccb67a
commit 1b25ccc30d
3 changed files with 31 additions and 18 deletions

View File

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

View File

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

View File

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