From 8fbc8ae7d1f649421f8648d19477efc696e2f82d Mon Sep 17 00:00:00 2001 From: chronolaw Date: Sat, 12 Oct 2024 10:33:15 +0800 Subject: [PATCH] code clean: start_sync_timer --- kong/clustering/services/sync/rpc.lua | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) 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