summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--misc/freeswitch/scripts/fax_daemon.lua43
-rw-r--r--misc/freeswitch/scripts/send_fax.lua14
2 files changed, 28 insertions, 29 deletions
diff --git a/misc/freeswitch/scripts/fax_daemon.lua b/misc/freeswitch/scripts/fax_daemon.lua
index 94d343a..0784890 100644
--- a/misc/freeswitch/scripts/fax_daemon.lua
+++ b/misc/freeswitch/scripts/fax_daemon.lua
@@ -5,38 +5,37 @@
local MAIN_LOOP_SLEEP_TIME = 30;
-- Set logger
-require "common.log"
+require 'common.log'
local log = common.log.Log:new()
-log.prefix = "### [faxdaemon] "
+log.prefix = '#F# [faxdaemon] '
-log:debug('Starting fax daemon');
+log:info('FAX_DAEMON start');
-local database = nil;
-local api = freeswitch.API();
+require 'common.database'
+local database = common.database.Database:new{ log = log }:connect();
+if not database:connected() then
+ log:error('FAX_DAEMON - cannot connect to Gemeinschaft database');
+ return;
+end
+local api = freeswitch.API();
+require 'dialplan.fax'
freeswitch.setGlobalVariable('gs_fax_daemon', 'true');
+
while freeswitch.getGlobalVariable("gs_fax_daemon") == 'true' do
- require 'common.database'
- local database = common.database.Database:new{ log = log }:connect();
-
- if not database:connected() then
- log:error("connection to Gemeinschaft database lost - retry in " .. MAIN_LOOP_SLEEP_TIME .. " seconds")
- else
- require 'dialplan.fax'
- local fax_documents = dialplan.fax.Fax:new{log=log, database=database}:queued_for_sending();
-
- for key, fax_document in pairs(fax_documents) do
- if table.getn(fax_document.destination_numbers) > 0 and tonumber(fax_document.retry_counter) > 0 then
- log:debug('FAX_DAEMON_LOOP - fax_document=', fax_document.id, '/', fax_document.uuid, ', number: ' .. fax_document.destination_numbers[1]);
- local result = api:executeString('luarun send_fax.lua ' .. fax_document.id);
- end
+ local fax_documents = dialplan.fax.Fax:new{log=log, database=database}:queued_for_sending();
+
+ for key, fax_document in pairs(fax_documents) do
+ if table.getn(fax_document.destination_numbers) > 0 and tonumber(fax_document.retry_counter) > 0 then
+ log:debug('FAX_DAEMON_LOOP - fax_document=', fax_document.id, '/', fax_document.uuid, ', number: ' .. fax_document.destination_numbers[1]);
+ local result = api:executeString('luarun send_fax.lua ' .. fax_document.id);
end
end
- database:release();
-
+
if freeswitch.getGlobalVariable("gs_fax_daemon") == 'true' then
freeswitch.msleep(MAIN_LOOP_SLEEP_TIME * 1000);
end
end
-log:debug('Exiting fax daemon');
+database:release();
+log:info('FAX_DAEMON exit');
diff --git a/misc/freeswitch/scripts/send_fax.lua b/misc/freeswitch/scripts/send_fax.lua
index 9b6ffce..4898cb8 100644
--- a/misc/freeswitch/scripts/send_fax.lua
+++ b/misc/freeswitch/scripts/send_fax.lua
@@ -6,9 +6,9 @@ local FAX_FILE_PATH = "/opt/GS5/public/uploads/fax_document/tiff/";
local FAX_ANSWERING_TIMEOUT = 20;
-- Set logger
-require "common.log"
+require 'common.log'
local log = common.log.Log:new()
-log.prefix = "### [sendfax] "
+log.prefix = '#F# [sendfax] '
local document_id = argv[1];
@@ -16,12 +16,12 @@ require 'common.database'
local database = common.database.Database:new{ log = log }:connect();
if not database:connected() then
- log:error('cannot connect to Gemeinschaft database');
+ log:error('FAX_SEND - cannot connect to Gemeinschaft database');
return
end
if not tonumber(document_id) then
- log:error('document id not specified');
+ log:error('FAX_SEND - document id not specified');
return
end
@@ -32,7 +32,7 @@ local fax_class = dialplan.fax.Fax:new(defaults);
local fax_document = fax_class:find_document_by_id(document_id);
if not fax_document then
- log:error('document ' .. document_id .. ' not found');
+ log:error('FAX_SEND - document ' .. document_id .. ' not found');
return
end
@@ -45,14 +45,14 @@ end
local fax_account = fax_class:find_by_id(fax_document.fax_account_id);
if not fax_account then
- log:error('fax account ' .. fax_document.fax_account_id .. ' not found');
+ log:error('FAX_SEND - fax account ' .. fax_document.fax_account_id .. ' not found');
return
end
local destination_number = fax_class:destination_number(document_id);
if not destination_number or tostring(destination_number) == '' then
- log:error('destination number not found');
+ log:error('FAX_SEND - destination number not found');
return
end