We've been hoping that mkdocs-material will ship the much anticipated search enhancements for some time, but it's time to recognize that we need to do something to improve the search results with how things work right now. This is a big commit that changes the titles of the various pages from the code-annotated synopsis to just the name of the function. This makes it much easier now to match things like `kumo.reject` directly, but `reject` remains awkward to find. I think this is the best that we can do at this time. A few functions have been annotated with the `status: deprecated` to show as deprecated in the toc/nav (shows with a little trash can next to the name).
1.9 KiB
throttle_insert_ready_queue
kumo.on('throttle_insert_ready_queue', function(message) end)
{{since('2024.11.08-d383b033')}}
!!! note
This event was actually added in 2024.06.10-84e84b89 but
with a broken event registration that prevented it from working.
That was corrected in the version shown above.
This event is triggered when a message is ready to move from its containing scheduled queue and into a ready queue.
Its purpose is to allow you to evaluate any throttles defined by your policy; see kumo.make_throttle() for more information on throttles.
Multiple instances of the throttle_insert_ready_queue event can be registered,
and they will be called in the order in which they were registered,
until all registered events are called, or until one explicitly
returns nil to signal that no more should be triggered.
The example below will limit each tenant to send no more than 1000 messages
per hour:
kumo.on('throttle_insert_ready_queue', function(msg)
-- limit each tenant to 1000/hr
local tenant = msg:get_meta 'tenant'
local throttle = kumo.make_throttle(
string.format('tenant-send-limit-%s', tenant),
'1000/hr'
)
throttle:delay_message_if_throttled(msg)
end)
This example allows each tenant to have an individual limit; you could load the limits from a data file or database if you prefer.
local function per_tenant_throttle(tenant_name)
-- default to 1000/hr unless otherwise overridden
local rate = '1000/hr'
if tenant_name == 'tenant_1' then
-- Allow increased rate for this tenant
rate = '10000/hr'
end
return kumo.make_throttle(
string.format('tenant-send-limit-%s', tenant_name),
rate
)
end
kumo.on('throttle_insert_ready_queue', function(msg)
local tenant = msg:get_meta 'tenant'
local throttle = per_tenant_throttle(tenant)
throttle:delay_message_if_throttled(msg)
end)