From ee90a5252b173fa490de9e3679c10874372ef61c Mon Sep 17 00:00:00 2001 From: lamson <171004297@qq.com> Date: Mon, 19 Feb 2024 21:39:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=95=B4=E5=90=88Notify=E6=A8=A1?= =?UTF-8?q?=E5=9D=97(=E5=BE=85=E5=AE=8C=E6=88=90)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 2 +- src/Common/Classes/ShardTable.php | 4 +-- src/Crontab/Crontab.php | 7 ++-- src/EventMainServerCreate.php | 11 ++----- src/Notify/EsNotify.php | 2 +- src/Notify/Feishu/Message/Base.php | 4 +-- src/Notify/Feishu/Message/Text.php | 2 +- src/Notify/Feishu/Message/Textarea.php | 2 +- src/Task/CreateSubTable.php | 2 +- src/Task/Error.php | 2 +- src/Task/SyncData.php | 4 +-- src/function.php | 44 +++++++++++++++++++++++--- 12 files changed, 57 insertions(+), 29 deletions(-) diff --git a/composer.json b/composer.json index f0feaab..d07995e 100644 --- a/composer.json +++ b/composer.json @@ -26,10 +26,10 @@ "easyswoole/i18n": "^1.0", "easyswoole/policy": "^1.0", "easyswoole/file-watcher": "^1.0", - "wonder-game/es-notify": "1.1.*", "easyswoole/tracker": "^1.1", "easyswoole/swoole-ide-helper": "^1.3", "easyswoole/words-match": "^1.1", + "easyswoole/wechat": "^2.0", "ext-json": "*", "ext-iconv": "*", "ext-mbstring": "*" diff --git a/src/Common/Classes/ShardTable.php b/src/Common/Classes/ShardTable.php index 92eda4c..04a5a85 100644 --- a/src/Common/Classes/ShardTable.php +++ b/src/Common/Classes/ShardTable.php @@ -60,7 +60,7 @@ public function checkPartition($day) if ($warning) { $msg = "检测到以下表分区不足{$day}天:" . implode('、', $warning); trace($msg, 'info', 'worker'); - dingtalk_text($msg); + notice($msg); wechat_notice($msg); } } @@ -202,7 +202,7 @@ private function _reMsg($msg = '', $code = 0) { if ($code > 0) { $title = '执行分区错误: '; - dingtalk_text("$title $msg", true); + notice("$title $msg"); wechat_notice("$title $msg"); } trace($msg, $code ? 'error' : 'info', 'crontab'); diff --git a/src/Crontab/Crontab.php b/src/Crontab/Crontab.php index 6abc88d..af35bfa 100644 --- a/src/Crontab/Crontab.php +++ b/src/Crontab/Crontab.php @@ -37,18 +37,15 @@ public function onException(\Throwable $throwable, int $taskId, int $workerIndex public function throwable($row, string $message) { trace($message, 'error'); -// Trigger::getInstance()->throwable(new \Exception($message)); - - $title = 'Crontab异常'; $text = implode(" \n\n ", [ - '### **' . $title . '**', + '### **Crontab异常**', '- 服务器: ' . config('SERVNAME'), '- 项 目:' . config('SERVER_NAME'), "- id: {$row['id']}", "- name: {$row['name']}", "- 详 情:$message", ]); - dingtalk_markdown($title, $text); + notice($text); } public function run(int $taskId, int $workerIndex) diff --git a/src/EventMainServerCreate.php b/src/EventMainServerCreate.php index 6e9b8c2..3d54c01 100644 --- a/src/EventMainServerCreate.php +++ b/src/EventMainServerCreate.php @@ -12,7 +12,7 @@ use EasySwoole\Socket\AbstractInterface\ParserInterface; use EasySwoole\Spl\SplBean; use EasySwoole\WordsMatch\WMServer; -use WonderGame\EsNotify\EsNotify; +use WonderGame\EsUtility\Notify\EsNotify; class EventMainServerCreate extends SplBean { @@ -50,11 +50,6 @@ class EventMainServerCreate extends SplBean 'reload_after' => null, // callback worker process reload 后 ]; - /** - * @var null ['key' => new EsNotify/Config([])] - */ - //protected $notifyConfig = null; - protected $consumerJobs = null; protected function initialize(): void @@ -265,8 +260,8 @@ static public function registerNotify() if ( ! is_array($val)) { continue; } - /* @var \WonderGame\EsNotify\DingTalk\Config|\WonderGame\EsNotify\WeChat\Config $cls */ - $cls = '\\WonderGame\\EsNotify\\' . ucfirst($key) . '\\Config'; + /* @var \WonderGame\EsUtility\Notify\DingTalk\Config|\WonderGame\EsUtility\Notify\WeChat\Config|\WonderGame\EsUtility\Notify\Feishu\Config $cls */ + $cls = '\\WonderGame\\EsUtility\\Notify\\' . ucfirst($key) . '\\Config'; foreach ($val as $k => $v) { EsNotify::getInstance()->register(new $cls($v, true), $key, $k); diff --git a/src/Notify/EsNotify.php b/src/Notify/EsNotify.php index 57f3af5..e004587 100644 --- a/src/Notify/EsNotify.php +++ b/src/Notify/EsNotify.php @@ -7,7 +7,7 @@ use WonderGame\EsUtility\Notify\Interfaces\MessageInterface; use WonderGame\EsUtility\Notify\Interfaces\NotifyInterface; -class EsUtility +class EsNotify { use Singleton; diff --git a/src/Notify/Feishu/Message/Base.php b/src/Notify/Feishu/Message/Base.php index 4110ff7..09d40f3 100644 --- a/src/Notify/Feishu/Message/Base.php +++ b/src/Notify/Feishu/Message/Base.php @@ -1,9 +1,9 @@ query($builder, true, $connectionName); } catch (\EasySwoole\Mysqli\Exception\Exception|\Throwable $e) { $title = '创建分表失败'; - dingtalk_text("$title [$connectionName . $fullName] : " . $e->getMessage()); + notice("$title [$connectionName . $fullName] : " . $e->getMessage()); wechat_notice("$title {$e->getMessage()}"); trace("$title [$connectionName . $fullName] : " . $e->getMessage(), 'error'); } diff --git a/src/Task/Error.php b/src/Task/Error.php index 5449861..e337e61 100644 --- a/src/Task/Error.php +++ b/src/Task/Error.php @@ -43,7 +43,7 @@ public function run(int $taskId, int $workerIndex) } $message = implode($this->warp, $data); - dingtalk_markdown($title, $message); + notice($message); $message = "$title: {$this->data['message']}, 文件 {$this->data['file']} 第 {$this->data['line']} 行"; wechat_warning($message); diff --git a/src/Task/SyncData.php b/src/Task/SyncData.php index 3cfcc91..69dd287 100644 --- a/src/Task/SyncData.php +++ b/src/Task/SyncData.php @@ -109,7 +109,7 @@ protected function doSync($className) $orgs[$pk] = is_bool($insertId) ? $data[$pk] : $insertId; } } catch (\Exception|\Throwable $e) { - dingtalk_text($msg = "数据同步失败 class:$className, 错误信息: {$e->getMessage()}"); + notice($msg = "数据同步失败 class:$className, 错误信息: {$e->getMessage()}"); wechat_notice($msg); trace("$msg, data: " . json_encode($data, JSON_UNESCAPED_UNICODE), 'info', 'sync'); } @@ -172,7 +172,7 @@ protected function _delete_report($className = '', $rowCount = 0, $sql = '') $ding .= "- 删除行数: {$rowCount}{$newline}"; $ding .= "- 执行SQL:{$sql}{$newline}"; $ding .= "- 如需误删恢复,请查日志关键字:{$this->delBakupKey}"; - dingtalk_markdown('数据删除通知', $ding, false); + notice($ding, '数据删除通知'); wechat_notice("$title $sql"); } } diff --git a/src/function.php b/src/function.php index aefe78d..9cc983c 100644 --- a/src/function.php +++ b/src/function.php @@ -9,10 +9,13 @@ use EasySwoole\Redis\Redis; use EasySwoole\RedisPool\RedisPool; use EasySwoole\Spl\SplArray; -use WonderGame\EsNotify\DingTalk\Message\Markdown; -use WonderGame\EsNotify\DingTalk\Message\Text; -use WonderGame\EsNotify\EsNotify; -use WonderGame\EsNotify\WeChat\Message\Notice; +use WonderGame\EsUtility\Notify\DingTalk\Message\Markdown; +use WonderGame\EsUtility\Notify\DingTalk\Message\Text; +use WonderGame\EsUtility\Notify\Feishu\Message\Textarea; +use WonderGame\EsUtility\Notify\Feishu\Message\Text AS FeishuText; +use WonderGame\EsUtility\Notify\Feishu\Message\Card; +use WonderGame\EsUtility\Notify\EsNotify; +use WonderGame\EsUtility\Notify\WeChat\Message\Notice; use WonderGame\EsUtility\Common\Classes\CtxRequest; use WonderGame\EsUtility\Common\Classes\LamJwt; use WonderGame\EsUtility\Common\Classes\Mysqli; @@ -571,6 +574,39 @@ function dingtalk_markdown($title = '', $text = '', $at = true, $name = 'default } +if ( ! function_exists('feishu_text')) { + function feishu_text($content = '', $at = true, $name = 'default') + { + EsNotify::getInstance()->doesOne('feishu', new FeishuText([ + 'content' => $content, + 'isAtAll' => $at + ]), $name); + } +} + + +if ( ! function_exists('feishu_textarea')) { + function feishu_textarea($content = '', $at = true, $name = 'default') + { + EsNotify::getInstance()->doesOne('feishu', new Textarea([ + 'content' => $content, + 'isAtAll' => $at + ]), $name); + } +} + + +if ( ! function_exists('feishu_card')) { + function feishu_card($content = '', $at = true, $name = 'default') + { + EsNotify::getInstance()->doesOne('feishu', new Card([ + 'content' => $content, + 'isAtAll' => $at + ]), $name); + } +} + + if ( ! function_exists('array_to_std')) { function array_to_std(array $array = []) {