Random strategy for ring groups

This commit is contained in:
koldoa
2015-09-01 18:33:26 +02:00
parent aa647adde3
commit 049580fd30
3 changed files with 38 additions and 1 deletions
@@ -160,6 +160,28 @@
--forward the ring group
session:execute("transfer", ring_group_forward_destination.." XML "..context);
else
--get the strategy of the ring group, if random, we use random() to order the destinations
sql = [[
SELECT
r.ring_group_strategy
FROM
v_ring_groups as r, v_ring_group_destinations as d
WHERE
d.ring_group_uuid = r.ring_group_uuid
AND d.ring_group_uuid = ']]..ring_group_uuid..[['
AND r.domain_uuid = ']]..domain_uuid..[['
AND r.ring_group_enabled = 'true'
]];
--freeswitch.consoleLog("notice", "SQL:" .. sql .. "\n");
assert(dbh:query(sql, function(row)
if (row.ring_group_strategy == "random") then
sql_order = 'random()'
else
sql_order='d.destination_delay, d.destination_number asc'
end
end));
--get the ring group destinations
sql = [[
SELECT
@@ -174,7 +196,7 @@
AND r.domain_uuid = ']]..domain_uuid..[['
AND r.ring_group_enabled = 'true'
ORDER BY
d.destination_delay, d.destination_number asc
]]..sql_order..[[
]];
--freeswitch.consoleLog("notice", "SQL:" .. sql .. "\n");
destinations = {};
@@ -293,6 +315,9 @@
if (ring_group_strategy == "sequence") then
delimiter = "|";
end
if (ring_group_strategy == "random") then
delimiter = "|";
end
if (ring_group_strategy == "simultaneous") then
delimiter = ",";
end