⚡ 添加 NEW_MSG
事件, 轮询消息队列时等待 NEW_MSG
事件
This commit is contained in:
parent
cda99ceca5
commit
5e7c0f3fd0
@ -292,7 +292,7 @@ function util_notify.send(msg)
|
|||||||
if code == nil then
|
if code == nil then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
if code == 200 then
|
if code >= 200 and code < 500 then
|
||||||
log.info("util_notify.send", "发送通知成功", "code:", code, "body:", body)
|
log.info("util_notify.send", "发送通知成功", "code:", code, "body:", body)
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
@ -305,6 +305,7 @@ end
|
|||||||
-- @param msg 消息内容
|
-- @param msg 消息内容
|
||||||
function util_notify.add(msg)
|
function util_notify.add(msg)
|
||||||
table.insert(msg_queue, msg)
|
table.insert(msg_queue, msg)
|
||||||
|
sys.publish("NEW_MSG")
|
||||||
log.debug("util_notify.add", "添加到消息队列, 当前队列长度:", #msg_queue)
|
log.debug("util_notify.add", "添加到消息队列, 当前队列长度:", #msg_queue)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -315,17 +316,17 @@ local function poll()
|
|||||||
local msg
|
local msg
|
||||||
while true do
|
while true do
|
||||||
-- 消息队列非空, 且网络已注册
|
-- 消息队列非空, 且网络已注册
|
||||||
if #msg_queue > 0 and mobile.status() == 1 then
|
if next(msg_queue) ~= nil and mobile.status() == 1 then
|
||||||
log.debug("util_notify.poll", "轮询消息队列中...", "当前队列长度:", #msg_queue)
|
log.debug("util_notify.poll", "轮询消息队列中, 当前队列长度:", #msg_queue)
|
||||||
msg = msg_queue[1]
|
msg = msg_queue[1]
|
||||||
if util_notify.send(msg) then
|
if util_notify.send(msg) then
|
||||||
table.remove(msg_queue, 1)
|
table.remove(msg_queue, 1)
|
||||||
sys.wait(100)
|
sys.wait(50)
|
||||||
else
|
else
|
||||||
sys.wait(2000)
|
sys.wait(2000)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
sys.wait(350)
|
sys.waitUntil("NEW_MSG", 1000 * 10)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user