Skip to content

Commit

Permalink
get_worker_name
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed Aug 22, 2024
1 parent 592683a commit eaf6b92
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lualib/resty/events/broker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ local lrucache = require "resty.lrucache"
local queue = require "resty.events.queue"
local utils = require "resty.events.utils"
local server = require("resty.events.protocol").server


local is_timeout = utils.is_timeout
local is_closed = utils.is_closed
local get_worker_name = utils.get_worker_name


local setmetatable = setmetatable
local random = math.random


local ngx = ngx -- luacheck: ignore
local log = ngx.log
local exit = ngx.exit
Expand All @@ -19,12 +24,15 @@ local ERR = ngx.ERR
local DEBUG = ngx.DEBUG
local NOTICE = ngx.NOTICE


local spawn = ngx.thread.spawn
local kill = ngx.thread.kill
local wait = ngx.thread.wait


local decode = codec.decode


local MAX_UNIQUE_EVENTS = 1024
local WEAK_KEYS_MT = { __mode = "k", }

Expand All @@ -39,12 +47,6 @@ do
end


local function get_worker_name(worker_id)
return worker_id == -1 and
"privileged agent" or "worker #" .. worker_id
end


local function terminating(self, worker_connection)
return not self._clients[worker_connection] or exiting()
end
Expand Down
8 changes: 8 additions & 0 deletions lualib/resty/events/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ local function is_closed(err)
end


local function get_worker_name(worker_id)
return worker_id == -1 and
"privileged agent" or "worker #" .. worker_id
end


return {
is_timeout = is_timeout,
is_closed = is_closed,

get_worker_name = get_worker_name,
}
9 changes: 9 additions & 0 deletions lualib/resty/events/worker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ local queue = require "resty.events.queue"
local callback = require "resty.events.callback"
local utils = require "resty.events.utils"


local frame_validate = require("resty.events.frame").validate
local client = require("resty.events.protocol").client
local is_timeout = utils.is_timeout
local get_worker_name = utils.get_worker_name


local type = type
local assert = assert
local setmetatable = setmetatable
local random = math.random


local ngx = ngx -- luacheck: ignore
local log = ngx.log
local sleep = ngx.sleep
Expand All @@ -22,19 +26,24 @@ local ERR = ngx.ERR
local DEBUG = ngx.DEBUG
local NOTICE = ngx.NOTICE


local spawn = ngx.thread.spawn
local kill = ngx.thread.kill
local wait = ngx.thread.wait


local timer_at = ngx.timer.at


local encode = codec.encode
local decode = codec.decode
local cjson_encode = cjson.encode


local EVENTS_COUNT_LIMIT = 100
local EVENTS_SLEEP_TIME = 0.05


local EMPTY_T = {}

local EVENT_T = {
Expand Down

0 comments on commit eaf6b92

Please sign in to comment.