From 5e7c0f3fd0cb2bcded92f157a60ed8e4d1a759dc Mon Sep 17 00:00:00 2001 From: Mizore Date: Thu, 9 Feb 2023 19:39:39 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20=E6=B7=BB=E5=8A=A0=20`NEW=5FMSG`=20?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6,=20=E8=BD=AE=E8=AF=A2=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E9=98=9F=E5=88=97=E6=97=B6=E7=AD=89=E5=BE=85=20`NEW=5FMSG`=20?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/util_notify.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/script/util_notify.lua b/script/util_notify.lua index d1d87b5..77fbe16 100644 --- a/script/util_notify.lua +++ b/script/util_notify.lua @@ -292,7 +292,7 @@ function util_notify.send(msg) if code == nil then return true end - if code == 200 then + if code >= 200 and code < 500 then log.info("util_notify.send", "发送通知成功", "code:", code, "body:", body) return true else @@ -305,6 +305,7 @@ end -- @param msg 消息内容 function util_notify.add(msg) table.insert(msg_queue, msg) + sys.publish("NEW_MSG") log.debug("util_notify.add", "添加到消息队列, 当前队列长度:", #msg_queue) end @@ -315,17 +316,17 @@ local function poll() local msg while true do -- 消息队列非空, 且网络已注册 - if #msg_queue > 0 and mobile.status() == 1 then - log.debug("util_notify.poll", "轮询消息队列中...", "当前队列长度:", #msg_queue) + if next(msg_queue) ~= nil and mobile.status() == 1 then + log.debug("util_notify.poll", "轮询消息队列中, 当前队列长度:", #msg_queue) msg = msg_queue[1] if util_notify.send(msg) then table.remove(msg_queue, 1) - sys.wait(100) + sys.wait(50) else sys.wait(2000) end else - sys.wait(350) + sys.waitUntil("NEW_MSG", 1000 * 10) end end end