local var = require("var")
if var.calc() == 1 then
ngx.say("ok")
else
ngx.status = ngx.HTTP_INTERNAL_SERVER_ERROR
ngx.say("error")
end
local count = 1
local _M = {}
local function add()
count = count + 1
end
local function sub()
count = count - 1
end
function _M.calc()
add()
-- 模拟协程调度
ngx.sleep(ngx.time()%0.003)
sub()
return count
end
return _M
init_worker_by_lua_block {
local delay = 5
local handler
handler = function()
counter = counter or 0
counter = counter + 1
ngx.log(ngx.ERR, counter)
local ok, err = ngx.timer.at(delay, handler)
if not ok then
ngx.log(ngx.ERR, "failed to create the timer: ", err)
return
end
end
local ok, err = ngx.timer.at(delay, handler)
if not ok then
ngx.log(ngx.ERR, "failed to create the timer: ", err)
return
end
}