Skip to content

Commit

Permalink
apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed Sep 4, 2024
1 parent cb9b21f commit 4df0347
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lualib/resty/events/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
16 changes: 13 additions & 3 deletions lualib/resty/events/utils.lua
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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,
}

0 comments on commit 4df0347

Please sign in to comment.