提交 b1b7d1fe authored 作者: Bret McDanel's avatar Bret McDanel

added the ability to schedule tasks on any machine or a named machine, currently…

added the ability to schedule tasks on any machine or a named machine, currently requires http://jira.freeswitch.org/browse/MODAPP-357 for the hostname function to know which host its running on


git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk/contrib@15219 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 7ffdb70e
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
-- acctid int(11) NOT NULL auto_increment, -- acctid int(11) NOT NULL auto_increment,
-- action varchar(1024) NOT NULL, -- action varchar(1024) NOT NULL,
-- timestamp timestamp NOT NULL, -- timestamp timestamp NOT NULL,
-- server varchar(64) NOT NULL DEFAULT '*',
-- primary key (acctid) -- primary key (acctid)
-- ); -- );
-- --
...@@ -63,6 +64,8 @@ ...@@ -63,6 +64,8 @@
-- may cause this script to totally freak -- may cause this script to totally freak
-- currently this script requires http://jira.freeswitch.org/browse/MODAPP-357
require "luasql.mysql" require "luasql.mysql"
-- Database setup -- Database setup
...@@ -137,10 +140,11 @@ ...@@ -137,10 +140,11 @@
env = assert (luasql.mysql()) env = assert (luasql.mysql())
dbcon = assert (env:connect(DATABASE,USERNAME,PASSWORD,DBHOST)) dbcon = assert (env:connect(DATABASE,USERNAME,PASSWORD,DBHOST))
blah = assert(dbcon:execute("CREATE TABLE if not exists "..TABLENAME.." (".. blah = assert(dbcon:execute("CREATE TABLE if not exists "..TABLENAME.." ("..
"acctid int(11) NOT NULL auto_increment,".. "acctid int(11) NOT NULL auto_increment,"..
"action varchar(1024) NOT NULL,".. "action varchar(1024) NOT NULL,"..
"timestamp timestamp NOT NULL,".. "timestamp timestamp NOT NULL,"..
"primary key (acctid)".. "server varchar(64) NOT NULL DEFAULT '*',"..
"primary key (acctid)"..
")")) ")"))
dbcon:close() dbcon:close()
env:close() env:close()
...@@ -152,6 +156,7 @@ ...@@ -152,6 +156,7 @@
-- does not work properly, that is really all we need -- does not work properly, that is really all we need
api = freeswitch.API() api = freeswitch.API()
hostname = api:execute("hostname")
if blah ~= 0 then if blah ~= 0 then
logger("Unable to connect to DB or create the table, something is broken.") logger("Unable to connect to DB or create the table, something is broken.")
...@@ -165,7 +170,7 @@ ...@@ -165,7 +170,7 @@
dbcon = assert (env:connect(DATABASE,USERNAME,PASSWORD,DBHOST)) dbcon = assert (env:connect(DATABASE,USERNAME,PASSWORD,DBHOST))
while true do while true do
assert (dbcon:execute("LOCK TABLE "..TABLENAME.." WRITE")) assert (dbcon:execute("LOCK TABLE "..TABLENAME.." WRITE"))
cur = assert (dbcon:execute("select * from "..TABLENAME.." where timestamp < NOW() order by timestamp desc limit 1")) cur = assert (dbcon:execute("select * from "..TABLENAME.." where timestamp < NOW() and (server = '"..hostname.."' or server = '*') order by timestamp limit 1"))
row = cur:fetch({},"a") row = cur:fetch({},"a")
if not row then if not row then
break break
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论