I'm trying to write a simple timer function to watch a specified key in etcd.
It seems that this funtion can work: When I change the value of key in etcd, it will get the changes as expected. But when there is no changes, "lua tcp socket read time out" keeps flushing in error.log.
After I execute openresty -s reload, the previous worker process will not exit and keep the status "worker process is shutting down" for a very long time (I even do not know if it will keep this status forever)
local cli, callback, err
cli, err = etcd.new(opts)
if err then
ngx.log(ngx.ERR, "new etcd err: " .. err)
ngx.timer.at(5, watch, self)
return
end
local attr = {}
attr["timeout"] = 3
callback, err = cli:watchdir(config["etcd"][env]["watch_prefix"], attr)
if err then
ngx.log(ngx.ERR, "get key error")
ngx.timer.at(5, watch, self)
return
end
local created_true = callback()
local watch_res = callback()
if watch_res then
ngx.log(ngx.INFO, serializeTable(watch_res))
end
ngx.sleep(0.5)
ngx.timer.at(0, watch, self)