2015-11-18 14:27:55 +01:00
|
|
|
require "resources.functions.config"
|
|
|
|
|
|
|
|
|
|
require "resources.functions.sleep"
|
|
|
|
|
local log = require "resources.functions.log".next_fax_task
|
|
|
|
|
local Tasks = require "fax_queue.tasks"
|
|
|
|
|
local Esl = require "resources.functions.esl"
|
|
|
|
|
|
|
|
|
|
local FAX_OPTIONS = {
|
|
|
|
|
"fax_use_ecm=false,fax_enable_t38=true,fax_enable_t38_request=true,fax_disable_v17=default";
|
|
|
|
|
"fax_use_ecm=true,fax_enable_t38=true,fax_enable_t38_request=true,fax_disable_v17=false";
|
|
|
|
|
"fax_use_ecm=true,fax_enable_t38=false,fax_enable_t38_request=false,fax_disable_v17=false";
|
|
|
|
|
"fax_use_ecm=true,fax_enable_t38=true,fax_enable_t38_request=true,fax_disable_v17=true";
|
|
|
|
|
"fax_use_ecm=false,fax_enable_t38=false,fax_enable_t38_request=false,fax_disable_v17=false";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
local function next_task()
|
|
|
|
|
local task, err = Tasks.next_task()
|
|
|
|
|
|
|
|
|
|
if not task then
|
|
|
|
|
if err then
|
|
|
|
|
log.noticef('Can not select next task: %s', tostring(err))
|
|
|
|
|
else
|
|
|
|
|
log.notice("No task")
|
|
|
|
|
end
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local esl
|
|
|
|
|
local ok, err = pcall(function()
|
|
|
|
|
|
|
|
|
|
local mode = (task.retry_counter % #FAX_OPTIONS) + 1
|
|
|
|
|
local dial_string = '{' ..
|
|
|
|
|
task.dial_string .. "api_hangup_hook='lua fax_queue/retry.lua'," ..
|
|
|
|
|
FAX_OPTIONS[mode] ..
|
|
|
|
|
'}' .. task.uri
|
|
|
|
|
|
|
|
|
|
local originate = 'originate ' .. dial_string .. ' &lua(fax_queue/exec.lua)'
|
|
|
|
|
|
|
|
|
|
log.notice(originate)
|
|
|
|
|
esl = assert(Esl.new())
|
2015-11-26 15:23:33 +01:00
|
|
|
local ok, status, info = esl:api(originate)
|
|
|
|
|
if not ok then
|
|
|
|
|
Tasks.wait_task(task, false, info)
|
2015-11-26 15:30:56 +01:00
|
|
|
if task.status ~= 0 then
|
|
|
|
|
Tasks.remove_task(task)
|
|
|
|
|
end
|
2015-11-26 15:23:33 +01:00
|
|
|
log.noticef('Can not originate to `%s` cause: %s: %s ', task.uri, tostring(status), tostring(info))
|
|
|
|
|
else
|
|
|
|
|
log.noticef("originate successfuly: %s", tostring(info))
|
|
|
|
|
end
|
2015-11-18 14:27:55 +01:00
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
if esl then esl:close() end
|
|
|
|
|
|
|
|
|
|
if not ok then
|
|
|
|
|
Tasks.release_task(task)
|
|
|
|
|
log.noticef("Error execute task: %s", tostring(err))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function poll_once()
|
|
|
|
|
Tasks.cleanup_tasks()
|
|
|
|
|
while next_task() do
|
|
|
|
|
sleep(5000)
|
|
|
|
|
end
|
|
|
|
|
Tasks.release_db()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
poll_once = poll_once;
|
|
|
|
|
}
|