Skip to content

Commit

Permalink
fix: only cache queue when concurrency is 1
Browse files Browse the repository at this point in the history
  • Loading branch information
vm-001 committed Aug 9, 2024
1 parent 6b92162 commit 744c5e6
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions kong/tools/queue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -241,16 +241,18 @@ local function get_or_create_queue(queue_conf, handler, handler_conf)

queue = setmetatable(queue, Queue_mt)

kong.timer:named_at("queue " .. key, 0, function(_, q)
while q:count() > 0 do
q:log_debug("processing queue")
q:process_once()
end
q:log_debug("done processing queue")
queues[key] = nil
end, queue)
if queue.concurrency == 1 then
kong.timer:named_at("queue " .. key, 0, function(_, q)
while q:count() > 0 do
q:log_debug("processing queue")
q:process_once()
end
q:log_debug("done processing queue")
queues[key] = nil
end, queue)
queues[key] = queue
end

queues[key] = queue

queue:log_debug("queue created")

Expand Down Expand Up @@ -636,7 +638,10 @@ function Queue.enqueue(queue_conf, handler, handler_conf, value)
"arg #1 (queue_conf) max_bytes must be a number or nil"
)

-- TODO: assert concurrency
assert(
type(queue_conf.concurrency) == "number",
"arg #1 (queue_conf) concurrency must be a number"
)

local queue = get_or_create_queue(queue_conf, handler, handler_conf)
return enqueue(queue, value)
Expand Down

0 comments on commit 744c5e6

Please sign in to comment.