Quantcast
Channel: Nginx Forum - How to...
Viewing all articles
Browse latest Browse all 4759

Lua timer and ngx.location.capture

$
0
0
Hello, how can I use ngx.timer.at and ngx.location.capture in same location ?

I trying some code but I get error !

rewrite_by_lua '
local delay = 1 -- in seconds
local dogs = ngx.shared.dogs

local status = dogs:get("Status")
if status == nil then
dogs:set("Status", 1)
end

local new_timer = ngx.timer.at
local log = ngx.log
local ERR = ngx.ERR
local check

check = function(premature)

if not premature then
local ok, err = new_timer(delay, check)
if ok then
if dogs:get("LuaChannels") == "stop" then
res = ngx.location.capture("/channel-stop?ch=1258")
dogs:set("LuaChannel", res.body)
dogs:set("LuaChannels", "")
end
return
end
end
end

local ok, err = new_timer(delay, check)
if ok then
if dogs:get("LuaChannels") == "stop" then
res = ngx.location.capture("/channel-stop?ch=1258")
dogs:set("LuaChannel", res.body)
dogs:set("LuaChannels", "")
end
return
end
';

On first call location the ngx.location.capture("/channel-stop?ch=1258") is working but not on next and I get error to error on log file

[error] 3756#4204: lua entry thread aborted: runtime error: rewrite_by_lua(nginx.conf:74):22: API disabled in the context of ngx.timer
stack traceback:
coroutine 0:
[C]: in function 'capture'
rewrite_by_lua(nginx.conf:74):22: in function <rewrite_by_lua(nginx.conf:74):15>, context: ngx.timer, client: 127.0.0.1, server: 0.0.0.0:8080

So I need to use timer when i seted dogs:get("LuaChannels") to start ngx.location.capture() and after that to reset functions until next call via dogs:get("LuaChannels") !?

I hope you are understand what I want .

Viewing all articles
Browse latest Browse all 4759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>