Skip to content

Commit

Permalink
fix(cluster) quiet keepalive events
Browse files Browse the repository at this point in the history
  • Loading branch information
subnetmarco committed Sep 20, 2016
1 parent 3d4d154 commit 6d0317d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
7 changes: 5 additions & 2 deletions kong/core/cluster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ local function send_keepalive(premature)
ngx_log(ngx.ERR, tostring(err))
elseif #nodes == 1 then
local node = nodes[1]
local _, err = singletons.dao.nodes:update(node, node, {ttl=singletons.configuration.cluster_ttl_on_failure})
local _, err = singletons.dao.nodes:update(node, node, {
ttl = singletons.configuration.cluster_ttl_on_failure,
quiet = true
})
if err then
ngx_log(ngx.ERR, tostring(err))
end
Expand All @@ -97,4 +100,4 @@ return {
create_timer(KEEPALIVE_INTERVAL, send_keepalive)
create_timer(ASYNC_AUTOJOIN_INTERVAL, async_autojoin) -- Only execute one time
end
}
}
17 changes: 11 additions & 6 deletions kong/dao/dao.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,13 @@ end
--- Insert a row.
-- Insert a given Lua table as a row in the related table.
-- @param[type=table] tbl Table to insert as a row.
-- @param[type=table] options Options to use for this insertion. (`ttl`: Time-to-live for this row, in seconds)
-- @param[type=table] options Options to use for this insertion. (`ttl`: Time-to-live for this row, in seconds, `quiet`: does not send event)
-- @treturn table res A table representing the insert row (with fields created during the insertion).
-- @treturn table err If an error occured, a table describing the issue.
function DAO:insert(tbl, options)
options = options or {}
check_arg(tbl, 1, "table")
check_arg(options, 2, "table")

local model = self.model_mt(tbl)
local ok, err = model:validate {dao = self}
Expand All @@ -124,7 +126,7 @@ function DAO:insert(tbl, options)
end

local res, err = self.db:insert(self.table, self.schema, model, self.constraints, options)
if not err then
if not err and not options.quiet then
event(self, event_types.ENTITY_CREATED, self.table, self.schema, res)
end
return ret_error(self.db.db_type, res, err)
Expand Down Expand Up @@ -249,15 +251,16 @@ end
-- with the one specified in `tbl` at once.
-- @param[type=table] tbl A table containing the new values for this row.
-- @param[type=table] filter_keys A table which must contain the primary key(s) to select the row to be updated.
-- @param[type=table] options Options to use for this update. (`full`: performs a full update of the entity).
-- @param[type=table] options Options to use for this update. (`full`: performs a full update of the entity, `quiet`: does not send event).
-- @treturn table res A table representing the updated entity.
-- @treturn table err If an error occured, a table describing the issue.
function DAO:update(tbl, filter_keys, options)
options = options or {}
check_arg(tbl, 1, "table")
check_not_empty(tbl, 1)
check_arg(filter_keys, 2, "table")
check_not_empty(filter_keys, 2)
options = options or {}
check_arg(options, 3, "table")

for k, v in pairs(filter_keys) do
if tbl[k] == nil then
Expand Down Expand Up @@ -291,7 +294,9 @@ function DAO:update(tbl, filter_keys, options)
if err then
return ret_error(self.db.db_type, nil, err)
elseif res then
event(self, event_types.ENTITY_UPDATED, self.table, self.schema, old)
if not options.quiet then
event(self, event_types.ENTITY_UPDATED, self.table, self.schema, old)
end
return setmetatable(res, nil)
end
end
Expand Down Expand Up @@ -351,4 +356,4 @@ function DAO:truncate()
return ret_error(self.db.db_type, self.db:truncate_table(self.table))
end

return DAO
return DAO

0 comments on commit 6d0317d

Please sign in to comment.