Removes intermediate alert queues - only leaves recipient queues

Implements #4366
This commit is contained in:
Simone Mainardi 2020-09-04 17:41:52 +02:00
parent 9fe21dac15
commit 85f555a908
14 changed files with 110 additions and 191 deletions

View file

@ -8,11 +8,13 @@ package.path = dirs.installdir .. "/scripts/lua/modules/pools/?.lua;" .. package
local alert_consts = require "alert_consts"
local pools = require "pools"
local notification_recipients = require "notification_recipients"
-- ################################################################################
local pools_alert_utils = {}
local alert_entity_pool_instances = {}
local alert_entity_all_pools = {}
-- ################################################################################
@ -66,4 +68,45 @@ end
-- ################################################################################
-- @brief Returns an array of recipient ids responsible for a given an `entity_id` and a `pool_id`
-- @param entity_id One of alert_consts.alert_entities
-- @param pool_id The pool id of an existing entity pool
-- @return An array of recipient ids
function pools_alert_utils.get_entity_recipients_by_pool_id(entity_id, pool_id)
local res = {}
local entity = alert_consts.alertEntityById(entity_id)
-- Obtain the pools instance for the given entity
local pools_instance = pools_alert_utils.get_entity_pools_by_id(entity_id)
if pools_instance then
-- tprint("found pool instance for "..entity.label)
-- See if the pools for the current instance are in cache
if not alert_entity_all_pools[entity_id] then
-- List of pools not yet cached, let's create it
alert_entity_all_pools[entity_id] = {}
local all_pools = pools_instance:get_all_pools()
-- It's handy to have the cache as a lua table with pool ids as keys and pool details as values
for _, pool in pairs(all_pools) do
alert_entity_all_pools[entity_id][pool.pool_id] = pool
end
end
-- Access the cache
local entity_pool = alert_entity_all_pools[entity_id][pool_id]
if entity_pool and entity_pool["recipients"] then
for _, recipient in pairs(entity_pool["recipients"]) do
-- Prepare the result with all the recipients
res[#res + 1] = recipient
-- tprint(string.format("Adding recipient [%s][%s][%i]", recipient, entity.label, pool_id))
end
end
end
return res
end
-- ################################################################################
return pools_alert_utils