From f3e844bb0aa8e2f1c4324141d50d279deb403dec Mon Sep 17 00:00:00 2001 From: jerry Date: Fri, 29 Jan 2021 22:27:10 +0800 Subject: [PATCH] update to 2.2.2 version fix QQBot error clean code --- composer.json | 2 +- src/ZM/Annotation/AnnotationParser.php | 3 +-- src/ZM/Annotation/CQ/CQMessage.php | 1 - src/ZM/Annotation/Http/HandleAfter.php | 1 - src/ZM/Annotation/Swoole/OnCloseEvent.php | 1 - src/ZM/Command/DaemonStatusCommand.php | 1 - src/ZM/Event/EventDispatcher.php | 5 +--- src/ZM/Event/ServerEventHandler.php | 4 +++ src/ZM/Http/Response.php | 2 -- src/ZM/Utils/CoMessage.php | 30 +++++++++++++++++++++++ src/ZM/Utils/ZMUtil.php | 4 +++ 11 files changed, 41 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index 504e47dd..7cb9bd2e 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "High performance QQ robot and web server development framework", "minimum-stability": "stable", "license": "Apache-2.0", - "version": "2.2.1", + "version": "2.2.2", "extra": { "exclude_annotate": [ "src/ZM" diff --git a/src/ZM/Annotation/AnnotationParser.php b/src/ZM/Annotation/AnnotationParser.php index 22e205e4..ff0d443b 100644 --- a/src/ZM/Annotation/AnnotationParser.php +++ b/src/ZM/Annotation/AnnotationParser.php @@ -9,11 +9,10 @@ use ZM\Console\Console; use ReflectionClass; use ReflectionException; use ReflectionMethod; -use ZM\Annotation\Http\{HandleAfter, HandleBefore, Controller, HandleException, Middleware, MiddlewareClass, RequestMapping}; +use ZM\Annotation\Http\{HandleAfter, HandleBefore, HandleException, Middleware, MiddlewareClass, RequestMapping}; use ZM\Annotation\Interfaces\Level; use ZM\Annotation\Module\Closed; use ZM\Http\RouteManager; -use ZM\Utils\DataProvider; class AnnotationParser { diff --git a/src/ZM/Annotation/CQ/CQMessage.php b/src/ZM/Annotation/CQ/CQMessage.php index 70917033..c3906087 100644 --- a/src/ZM/Annotation/CQ/CQMessage.php +++ b/src/ZM/Annotation/CQ/CQMessage.php @@ -3,7 +3,6 @@ namespace ZM\Annotation\CQ; -use Doctrine\Common\Annotations\Annotation\Required; use Doctrine\Common\Annotations\Annotation\Target; use ZM\Annotation\AnnotationBase; use ZM\Annotation\Interfaces\Level; diff --git a/src/ZM/Annotation/Http/HandleAfter.php b/src/ZM/Annotation/Http/HandleAfter.php index 9d2e43a4..9a378a71 100644 --- a/src/ZM/Annotation/Http/HandleAfter.php +++ b/src/ZM/Annotation/Http/HandleAfter.php @@ -4,7 +4,6 @@ namespace ZM\Annotation\Http; -use Doctrine\Common\Annotations\Annotation\Required; use Doctrine\Common\Annotations\Annotation\Target; use ZM\Annotation\AnnotationBase; diff --git a/src/ZM/Annotation/Swoole/OnCloseEvent.php b/src/ZM/Annotation/Swoole/OnCloseEvent.php index d0ea70ee..3f791ac9 100644 --- a/src/ZM/Annotation/Swoole/OnCloseEvent.php +++ b/src/ZM/Annotation/Swoole/OnCloseEvent.php @@ -5,7 +5,6 @@ namespace ZM\Annotation\Swoole; use Doctrine\Common\Annotations\Annotation\Target; -use ZM\Annotation\Interfaces\Rule; /** * @Annotation diff --git a/src/ZM/Command/DaemonStatusCommand.php b/src/ZM/Command/DaemonStatusCommand.php index 28201383..a1c8403f 100644 --- a/src/ZM/Command/DaemonStatusCommand.php +++ b/src/ZM/Command/DaemonStatusCommand.php @@ -6,7 +6,6 @@ namespace ZM\Command; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use ZM\Utils\DataProvider; class DaemonStatusCommand extends DaemonCommand { diff --git a/src/ZM/Event/EventDispatcher.php b/src/ZM/Event/EventDispatcher.php index 21bb3eab..4781cff7 100644 --- a/src/ZM/Event/EventDispatcher.php +++ b/src/ZM/Event/EventDispatcher.php @@ -104,10 +104,7 @@ class EventDispatcher } catch (InterruptException $e) { $this->store = $e->return_var; $this->status = self::STATUS_INTERRUPTED; - } catch (Exception $e) { - $this->status = self::STATUS_EXCEPTION; - throw $e; - } catch (Error $e) { + } catch (Exception | Error $e) { $this->status = self::STATUS_EXCEPTION; throw $e; } diff --git a/src/ZM/Event/ServerEventHandler.php b/src/ZM/Event/ServerEventHandler.php index 72786b9e..4d3f0d9f 100644 --- a/src/ZM/Event/ServerEventHandler.php +++ b/src/ZM/Event/ServerEventHandler.php @@ -501,6 +501,10 @@ class ServerEventHandler //unset(Context::$context[Co::getCid()]); $data = json_decode($data, true); switch ($data["action"] ?? '') { + case "resume_ws_message": + $obj = $data["data"]; + Co::resume($obj["coroutine"]); + break; case "getWorkerCache": $r = WorkerCache::get($data["key"]); $action = ["action" => "returnWorkerCache", "cid" => $data["cid"], "value" => $r]; diff --git a/src/ZM/Http/Response.php b/src/ZM/Http/Response.php index 31686d06..24fe266d 100644 --- a/src/ZM/Http/Response.php +++ b/src/ZM/Http/Response.php @@ -4,8 +4,6 @@ namespace ZM\Http; -use ZM\Console\Console; - class Response { diff --git a/src/ZM/Utils/CoMessage.php b/src/ZM/Utils/CoMessage.php index b19fb307..637f56f7 100644 --- a/src/ZM/Utils/CoMessage.php +++ b/src/ZM/Utils/CoMessage.php @@ -48,4 +48,34 @@ class CoMessage if ($result === null) return false; return $result; } + + public static function resumeByWS() { + $dat = ctx()->getData(); + $last = null; + SpinLock::lock("wait_api"); + $all = LightCacheInside::get("wait_api", "wait_api") ?? []; + foreach ($all as $k => $v) { + if(!isset($v["compare"])) continue; + foreach ($v["compare"] as $vs) { + if ($v[$vs] != ($dat[$vs] ?? null)) { + continue 2; + } + } + $last = $k; + } + if($last !== null) { + $all[$last]["result"] = $dat; + LightCacheInside::set("wait_api", "wait_api", $all); + SpinLock::unlock("wait_api"); + if ($all[$last]["worker_id"] != server()->worker_id) { + ZMUtil::sendActionToWorker($all[$k]["worker_id"], "resume_ws_message", $all[$last]); + } else { + Co::resume($all[$last]["coroutine"]); + } + return true; + } else { + SpinLock::unlock("wait_api"); + return false; + } + } } diff --git a/src/ZM/Utils/ZMUtil.php b/src/ZM/Utils/ZMUtil.php index 8056f9bc..a4a3e949 100644 --- a/src/ZM/Utils/ZMUtil.php +++ b/src/ZM/Utils/ZMUtil.php @@ -51,4 +51,8 @@ class ZMUtil return ZMBuf::$instance[$class]; } } + + public static function sendActionToWorker($target_id, $action, $data) { + server()->sendMessage(json_encode(["action" => $action, "data" => $data]), $target_id); + } }