Fix. Properly handle error from memcached when load configs. (#2641)
On my system mod_memcached returns `-ERR SOME ERRORS WERE REPORTED` when memcached service not available. And sofia.conf.lua does not handle this case and interpret this response as valid one. Using `cache` class allows handle such errors. Also this class handle all escaping operation which makes code more clear.
This commit is contained in:
parent
cfeb809900
commit
46f74ab726
|
|
@ -33,14 +33,21 @@
|
||||||
]]
|
]]
|
||||||
|
|
||||||
--get the cache
|
--get the cache
|
||||||
if (trim(api:execute("module_exists", "mod_memcache")) == "true") then
|
local cache = require "resources.functions.cache"
|
||||||
XML_STRING = trim(api:execute("memcache", "get configuration:acl.conf"));
|
local acl_cache_key = "configuration:acl.conf"
|
||||||
else
|
XML_STRING, err = cache.get(acl_cache_key)
|
||||||
XML_STRING = "-ERR NOT FOUND";
|
|
||||||
end
|
|
||||||
|
|
||||||
--set the cache
|
--set the cache
|
||||||
if (XML_STRING == "-ERR NOT FOUND") or (XML_STRING == "-ERR CONNECTION FAILURE") then
|
if not XML_STRING then
|
||||||
|
--log cache error
|
||||||
|
if (debug["cache"]) then
|
||||||
|
freeswitch.consoleLog("warning", "[xml_handler] " .. acl_cache_key .. " can not be get from memcache: " .. tostring(err) .. "\n");
|
||||||
|
end
|
||||||
|
|
||||||
|
--log cache error
|
||||||
|
if (debug["cache"]) then
|
||||||
|
freeswitch.consoleLog("warning", "[xml_handler] configuration:acl.conf can not be get from memcache: " .. tostring(err) .. "\n");
|
||||||
|
end
|
||||||
|
|
||||||
--set a default value
|
--set a default value
|
||||||
if (expire["acl"] == nil) then
|
if (expire["acl"] == nil) then
|
||||||
|
|
@ -115,7 +122,14 @@
|
||||||
dbh:release();
|
dbh:release();
|
||||||
|
|
||||||
--set the cache
|
--set the cache
|
||||||
result = trim(api:execute("memcache", "set configuration:acl.conf '"..XML_STRING:gsub("'", "'").."' "..expire["acl"]));
|
local ok, err = cache.set(acl_cache_key, XML_STRING, expire["acl"]);
|
||||||
|
if debug["cache"] then
|
||||||
|
if ok then
|
||||||
|
freeswitch.consoleLog("notice", "[xml_handler] " .. acl_cache_key .. " stored in memcache\n");
|
||||||
|
else
|
||||||
|
freeswitch.consoleLog("warning", "[xml_handler] " .. acl_cache_key .. " can not be stored in memcache: " .. tostring(err) .. "\n");
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--send the xml to the console
|
--send the xml to the console
|
||||||
if (debug["xml_string"]) then
|
if (debug["xml_string"]) then
|
||||||
|
|
@ -126,14 +140,11 @@
|
||||||
|
|
||||||
--send to the console
|
--send to the console
|
||||||
if (debug["cache"]) then
|
if (debug["cache"]) then
|
||||||
freeswitch.consoleLog("notice", "[xml_handler] configuration:acl.conf source: database\n");
|
freeswitch.consoleLog("notice", "[xml_handler] " .. acl_cache_key .. " source: database\n");
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
--replace the ' back to a single quote
|
|
||||||
XML_STRING = XML_STRING:gsub("'", "'");
|
|
||||||
|
|
||||||
--send to the console
|
--send to the console
|
||||||
if (debug["cache"]) then
|
if (debug["cache"]) then
|
||||||
freeswitch.consoleLog("notice", "[xml_handler] configuration:acl.conf source: memcache\n");
|
freeswitch.consoleLog("notice", "[xml_handler] " .. acl_cache_key .. " source: memcache\n");
|
||||||
end
|
end
|
||||||
end --if XML_STRING
|
end --if XML_STRING
|
||||||
|
|
|
||||||
|
|
@ -28,15 +28,17 @@
|
||||||
require "resources.functions.format_ringback"
|
require "resources.functions.format_ringback"
|
||||||
|
|
||||||
--get the cache
|
--get the cache
|
||||||
|
local cache = require "resources.functions.cache"
|
||||||
hostname = trim(api:execute("switchname", ""));
|
hostname = trim(api:execute("switchname", ""));
|
||||||
if (trim(api:execute("module_exists", "mod_memcache")) == "true") then
|
local cc_cache_key = "configuration:callcenter.conf:" .. hostname
|
||||||
XML_STRING = trim(api:execute("memcache", "get configuration:callcenter.conf:" .. hostname));
|
XML_STRING, err = cache.get(cc_cache_key)
|
||||||
else
|
|
||||||
XML_STRING = "-ERR NOT FOUND";
|
|
||||||
end
|
|
||||||
|
|
||||||
--set the cache
|
--set the cache
|
||||||
if (XML_STRING == "-ERR NOT FOUND") or (XML_STRING == "-ERR CONNECTION FAILURE") then
|
if not XML_STRING then
|
||||||
|
--log cache error
|
||||||
|
if (debug["cache"]) then
|
||||||
|
freeswitch.consoleLog("warning", "[xml_handler] " .. cc_cache_key .. " can not be get from memcache: " .. tostring(err) .. "\n");
|
||||||
|
end
|
||||||
|
|
||||||
--connect to the database
|
--connect to the database
|
||||||
local Database = require "resources.functions.database";
|
local Database = require "resources.functions.database";
|
||||||
|
|
@ -282,7 +284,14 @@
|
||||||
--freeswitch.consoleLog("notice", "[xml_handler]"..api:execute("eval ${dsn}"));
|
--freeswitch.consoleLog("notice", "[xml_handler]"..api:execute("eval ${dsn}"));
|
||||||
|
|
||||||
--set the cache
|
--set the cache
|
||||||
result = trim(api:execute("memcache", "set configuration:callcenter.conf:" .. hostname .." '"..XML_STRING:gsub("'", "'").."' ".."expire['callcenter.conf']"));
|
local ok, err = cache.set(cc_cache_key, XML_STRING, expire["callcenter"]);
|
||||||
|
if debug["cache"] then
|
||||||
|
if ok then
|
||||||
|
freeswitch.consoleLog("notice", "[xml_handler] " .. cc_cache_key .. " stored in memcache\n");
|
||||||
|
else
|
||||||
|
freeswitch.consoleLog("warning", "[xml_handler] " .. cc_cache_key .. " can not be stored in memcache: " .. tostring(err) .. "\n");
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--send the xml to the console
|
--send the xml to the console
|
||||||
if (debug["xml_string"]) then
|
if (debug["xml_string"]) then
|
||||||
|
|
@ -293,13 +302,11 @@
|
||||||
|
|
||||||
--send to the console
|
--send to the console
|
||||||
if (debug["cache"]) then
|
if (debug["cache"]) then
|
||||||
freeswitch.consoleLog("notice", "[xml_handler] configuration:callcenter.conf:" .. hostname .." source: database\n");
|
freeswitch.consoleLog("notice", "[xml_handler] " .. cc_cache_key .. " source: database\n");
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
--replace the ' back to a single quote
|
|
||||||
XML_STRING = XML_STRING:gsub("'", "'");
|
|
||||||
--send to the console
|
--send to the console
|
||||||
if (debug["cache"]) then
|
if (debug["cache"]) then
|
||||||
freeswitch.consoleLog("notice", "[xml_handler] configuration:callcenter.conf source: memcache\n");
|
freeswitch.consoleLog("notice", "[xml_handler] " .. cc_cache_key .. " source: memcache\n");
|
||||||
end
|
end
|
||||||
end --if XML_STRING
|
end --if XML_STRING
|
||||||
|
|
|
||||||
|
|
@ -30,14 +30,17 @@
|
||||||
local log = require "resources.functions.log".ivr_menu
|
local log = require "resources.functions.log".ivr_menu
|
||||||
|
|
||||||
--get the cache
|
--get the cache
|
||||||
if (trim(api:execute("module_exists", "mod_memcache")) == "true") then
|
local cache = require "resources.functions.cache"
|
||||||
XML_STRING = trim(api:execute("memcache", "get configuration:ivr.conf:" .. ivr_menu_uuid));
|
local ivr_menu_cache_key = "configuration:ivr.conf:" .. ivr_menu_uuid
|
||||||
else
|
XML_STRING, err = cache.get(ivr_menu_cache_key)
|
||||||
XML_STRING = "-ERR NOT FOUND";
|
|
||||||
end
|
|
||||||
|
|
||||||
--set the cache
|
--set the cache
|
||||||
if (XML_STRING == "-ERR NOT FOUND" or XML_STRING == "-ERR CONNECTION FAILURE") then
|
if not XML_STRING then
|
||||||
|
--log cache error
|
||||||
|
if (debug["cache"]) then
|
||||||
|
freeswitch.consoleLog("warning", "[xml_handler] " .. ivr_menu_cache_key .. " can not be get from memcache: " .. tostring(err) .. "\n");
|
||||||
|
end
|
||||||
|
|
||||||
--required includes
|
--required includes
|
||||||
local Database = require "resources.functions.database"
|
local Database = require "resources.functions.database"
|
||||||
local Settings = require "resources.functions.lazy_settings"
|
local Settings = require "resources.functions.lazy_settings"
|
||||||
|
|
@ -268,7 +271,14 @@
|
||||||
--freeswitch.consoleLog("notice", "[xml_handler]"..api:execute("eval ${dsn}"));
|
--freeswitch.consoleLog("notice", "[xml_handler]"..api:execute("eval ${dsn}"));
|
||||||
|
|
||||||
--set the cache
|
--set the cache
|
||||||
result = trim(api:execute("memcache", "set configuration:ivr.conf:".. ivr_menu_uuid .." '"..XML_STRING:gsub("'", "'").."' "..expire['ivr']));
|
local ok, err = cache.set(ivr_menu_uuid, XML_STRING, expire["ivr"]);
|
||||||
|
if debug["cache"] then
|
||||||
|
if ok then
|
||||||
|
freeswitch.consoleLog("notice", "[xml_handler] " .. ivr_menu_uuid .. " stored in memcache\n");
|
||||||
|
else
|
||||||
|
freeswitch.consoleLog("warning", "[xml_handler] " .. ivr_menu_uuid .. " can not be stored in memcache: " .. tostring(err) .. "\n");
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--send the xml to the console
|
--send the xml to the console
|
||||||
if (debug["xml_string"]) then
|
if (debug["xml_string"]) then
|
||||||
|
|
@ -279,14 +289,12 @@
|
||||||
|
|
||||||
--send to the console
|
--send to the console
|
||||||
if (debug["cache"]) then
|
if (debug["cache"]) then
|
||||||
freeswitch.consoleLog("notice", "[xml_handler] configuration:ivr.conf:" .. ivr_menu_uuid .." source: database\n");
|
freeswitch.consoleLog("notice", "[xml_handler] " .. ivr_menu_cache_key .. " source: database\n");
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
--replace the ' back to a single quote
|
|
||||||
XML_STRING = XML_STRING:gsub("'", "'");
|
|
||||||
--send to the console
|
--send to the console
|
||||||
if (debug["cache"]) then
|
if (debug["cache"]) then
|
||||||
freeswitch.consoleLog("notice", "[xml_handler] configuration:ivr.conf" .. ivr_menu_uuid .." source: memcache\n");
|
freeswitch.consoleLog("notice", "[xml_handler] " .. ivr_menu_cache_key .. " source: memcache\n");
|
||||||
end
|
end
|
||||||
end --if XML_STRING
|
end --if XML_STRING
|
||||||
|
|
|
||||||
|
|
@ -25,15 +25,17 @@
|
||||||
-- POSSIBILITY OF SUCH DAMAGE.
|
-- POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
--get the cache
|
--get the cache
|
||||||
hostname = trim(api:execute("switchname", ""));
|
local cache = require "resources.functions.cache"
|
||||||
if (trim(api:execute("module_exists", "mod_memcache")) == "true") then
|
local hostname = trim(api:execute("switchname", ""))
|
||||||
XML_STRING = trim(api:execute("memcache", "get configuration:sofia.conf:" .. hostname));
|
local sofia_cache_key = "configuration:sofia.conf:" .. hostname
|
||||||
else
|
XML_STRING, err = cache.get(sofia_cache_key)
|
||||||
XML_STRING = "-ERR NOT FOUND";
|
|
||||||
end
|
|
||||||
|
|
||||||
--set the cache
|
--set the cache
|
||||||
if (XML_STRING == "-ERR NOT FOUND") or (XML_STRING == "-ERR CONNECTION FAILURE") then
|
if not XML_STRING then
|
||||||
|
--log cache error
|
||||||
|
if (debug["cache"]) then
|
||||||
|
freeswitch.consoleLog("warning", "[xml_handler] " .. sofia_cache_key .. " can not be get from memcache: " .. tostring(err) .. "\n");
|
||||||
|
end
|
||||||
|
|
||||||
--set a default value
|
--set a default value
|
||||||
if (expire["sofia"] == nil) then
|
if (expire["sofia"] == nil) then
|
||||||
|
|
@ -296,7 +298,14 @@
|
||||||
dbh:release();
|
dbh:release();
|
||||||
|
|
||||||
--set the cache
|
--set the cache
|
||||||
result = trim(api:execute("memcache", "set configuration:sofia.conf:" .. hostname .." '"..XML_STRING:gsub("'", "'").."' "..expire["sofia"]));
|
local ok, err = cache.set(sofia_cache_key, XML_STRING, expire["sofia"])
|
||||||
|
if debug["cache"] then
|
||||||
|
if ok then
|
||||||
|
freeswitch.consoleLog("notice", "[xml_handler] " .. sofia_cache_key .. " stored in memcache\n");
|
||||||
|
else
|
||||||
|
freeswitch.consoleLog("warning", "[xml_handler] " .. sofia_cache_key .. " can not be stored in memcache: " .. tostring(err) .. "\n");
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--send the xml to the console
|
--send the xml to the console
|
||||||
if (debug["xml_string"]) then
|
if (debug["xml_string"]) then
|
||||||
|
|
@ -307,14 +316,11 @@
|
||||||
|
|
||||||
--send to the console
|
--send to the console
|
||||||
if (debug["cache"]) then
|
if (debug["cache"]) then
|
||||||
freeswitch.consoleLog("notice", "[xml_handler] configuration:sofia.conf:" .. hostname .." source: database\n");
|
freeswitch.consoleLog("notice", "[xml_handler] " .. sofia_cache_key .. " source: database\n");
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
--replace the ' back to a single quote
|
|
||||||
XML_STRING = XML_STRING:gsub("'", "'");
|
|
||||||
|
|
||||||
--send to the console
|
--send to the console
|
||||||
if (debug["cache"]) then
|
if (debug["cache"]) then
|
||||||
freeswitch.consoleLog("notice", "[xml_handler] configuration:sofia.conf source: memcache\n");
|
freeswitch.consoleLog("notice", "[xml_handler] " .. sofia_cache_key .. " source: memcache\n");
|
||||||
end
|
end
|
||||||
end --if XML_STRING
|
end --if XML_STRING
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue