Skip to content

Commit

Permalink
feat: 整合Notify模块(待完成)
Browse files Browse the repository at this point in the history
  • Loading branch information
linkunyuan committed Feb 19, 2024
1 parent 141e8d9 commit ee90a52
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 29 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*"
Expand Down
4 changes: 2 additions & 2 deletions src/Common/Classes/ShardTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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');
Expand Down
7 changes: 2 additions & 5 deletions src/Crontab/Crontab.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 3 additions & 8 deletions src/EventMainServerCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Notify/EsNotify.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use WonderGame\EsUtility\Notify\Interfaces\MessageInterface;
use WonderGame\EsUtility\Notify\Interfaces\NotifyInterface;

class EsUtility
class EsNotify
{
use Singleton;

Expand Down
4 changes: 2 additions & 2 deletions src/Notify/Feishu/Message/Base.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace WonderGame\EsUtility\Feishu\Message;
namespace WonderGame\EsUtility\Notify\Feishu\Message;

use EasySwoole\Spl\SplBean;
use WonderGame\EsUtility\Interfaces\MessageInterface;
use WonderGame\EsUtility\Notify\Interfaces\MessageInterface;

abstract class Base extends SplBean implements MessageInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Notify/Feishu/Message/Text.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace WonderGame\EsUtility\Feishu\Message;
namespace WonderGame\EsUtility\Notify\Feishu\Message;

class Text extends Base
{
Expand Down
2 changes: 1 addition & 1 deletion src/Notify/Feishu/Message/Textarea.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace WonderGame\EsUtility\Feishu\Message;
namespace WonderGame\EsUtility\Notify\Feishu\Message;

class Textarea extends Base
{
Expand Down
2 changes: 1 addition & 1 deletion src/Task/CreateSubTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected function doCreate($className = '')
DbManager::getInstance()->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');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Task/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Task/SyncData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down Expand Up @@ -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");
}
}
44 changes: 40 additions & 4 deletions src/function.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = [])
{
Expand Down

0 comments on commit ee90a52

Please sign in to comment.