make sure first backend sync happens in timer phase

This commit is contained in:
Elvin Efendi 2020-04-30 09:12:50 -04:00
parent 81514a50c1
commit 3b217cf766

View file

@ -248,11 +248,18 @@ local function get_balancer()
end end
function _M.init_worker() function _M.init_worker()
sync_backends() -- when worker starts, sync backends without delay -- when worker starts, sync backends without delay
local _, err = ngx.timer.every(BACKENDS_SYNC_INTERVAL, sync_backends) -- we call it in timer because for endpoints that require
if err then -- DNS resolution it needs to use socket which is not avalable in
ngx.log(ngx.ERR, "error when setting up timer.every for sync_backends: ", -- init_worker phase
tostring(err)) local ok, err = ngx.timer.at(0, sync_backends)
if not ok then
ngx.log(ngx.ERR, "failed to create timer: ", err)
end
ok, err = ngx.timer.every(BACKENDS_SYNC_INTERVAL, sync_backends)
if not ok then
ngx.log(ngx.ERR, "error when setting up timer.every for sync_backends: ", err)
end end
end end