diff --git a/lualib/resty/events/init.lua b/lualib/resty/events/init.lua index aaff5cd..6b60db8 100644 --- a/lualib/resty/events/init.lua +++ b/lualib/resty/events/init.lua @@ -12,7 +12,7 @@ local setmetatable = setmetatable local str_sub = string.sub -local worker_count = ngx.worker.count() -- luacheck: ignore +local worker_count = utils.get_worker_count() local _M = { diff --git a/lualib/resty/events/utils.lua b/lualib/resty/events/utils.lua index e149eec..c49c828 100644 --- a/lualib/resty/events/utils.lua +++ b/lualib/resty/events/utils.lua @@ -1,5 +1,9 @@ local str_sub = string.sub -local ngx_worker_id = ngx.worker.id -- luacheck: ignore + + +local ngx = ngx -- luacheck: ignore +local ngx_worker_id = ngx.worker.id +local ngx_worker_count = ngx.worker.count() local function is_timeout(err) @@ -14,20 +18,26 @@ end local function get_worker_id() - return ngx_worker_id() or -1 + return ngx_worker_id() or -1 -- -1 represents priviledged worker end local function get_worker_name(worker_id) - return worker_id == -1 and + return worker_id == -1 and -- -1 represents priviledged worker "privileged agent" or "worker #" .. worker_id end +local function get_worker_count() + return ngx_worker_count() +end + + return { is_timeout = is_timeout, is_closed = is_closed, get_worker_id = get_worker_id, get_worker_name = get_worker_name, + get_worker_count = get_worker_count, }