diff --git a/kong/clustering/services/sync/rpc.lua b/kong/clustering/services/sync/rpc.lua index fdf6ae98529f..c184d99c132f 100644 --- a/kong/clustering/services/sync/rpc.lua +++ b/kong/clustering/services/sync/rpc.lua @@ -319,8 +319,8 @@ local function do_sync(premature) end -function _M:sync_once(delay) - local hdl, err = ngx.timer.at(delay or 0, do_sync) +local function start_sync_timer(timer_func, delay) + local hdl, err = timer_func(delay or 0, do_sync) if not hdl then return nil, err @@ -330,14 +330,13 @@ function _M:sync_once(delay) end -function _M:sync_every(delay) - local hdl, err = ngx.timer.every(delay, do_sync) +function _M:sync_once(delay) + return start_sync_timer(ngx.timer.at, delay or 0) +end - if not hdl then - return nil, err - end - return true +function _M:sync_every(delay) + return start_sync_timer(ngx.timer.every, delay) end