Revision
15219
Author
trixter
Date
2009-10-23 17:30:19 -0500 (Fri, 23 Oct 2009)

Log Message

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

Modified Paths

Diff

Modified: freeswitch/trunk/contrib/trixter/scheduled_event.lua (15218 => 15219)


--- freeswitch/trunk/contrib/trixter/scheduled_event.lua	2009-10-23 22:04:34 UTC (rev 15218)
+++ freeswitch/trunk/contrib/trixter/scheduled_event.lua	2009-10-23 22:30:19 UTC (rev 15219)
@@ -47,6 +47,7 @@
 --    acctid int(11) NOT NULL auto_increment,
 --    action varchar(1024) NOT NULL,
 --    timestamp timestamp NOT NULL,
+--    server varchar(64) NOT NULL DEFAULT '*',
 --    primary key (acctid)
 -- );
 --
@@ -63,6 +64,8 @@
 -- may cause this script to totally freak
 
 
+-- currently this script requires http://jira.freeswitch.org/browse/MODAPP-357
+
    require "luasql.mysql"
    
    -- Database setup
@@ -137,10 +140,11 @@
    env = assert (luasql.mysql())
    dbcon = assert (env:connect(DATABASE,USERNAME,PASSWORD,DBHOST))
    blah = assert(dbcon:execute("CREATE TABLE if not exists "..TABLENAME.." ("..
-			"acctid int(11) NOT NULL auto_increment,"..
-			"action varchar(1024) NOT NULL,"..
-			"timestamp timestamp NOT NULL,"..
-			"primary key (acctid)"..
+			       "acctid int(11) NOT NULL auto_increment,"..
+			       "action varchar(1024) NOT NULL,"..
+			       "timestamp timestamp NOT NULL,"..
+			       "server varchar(64) NOT NULL DEFAULT '*',"..
+			       "primary key (acctid)"..
 			       ")"))
    dbcon:close()
    env:close()
@@ -152,6 +156,7 @@
                                          -- does not work properly, that is really all we need
    api = freeswitch.API()
 
+   hostname = api:execute("hostname")
 
    if blah ~= 0 then
       logger("Unable to connect to DB or create the table, something is broken.")
@@ -165,7 +170,7 @@
 	    dbcon = assert (env:connect(DATABASE,USERNAME,PASSWORD,DBHOST))
 	    while true do
 	       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")
 	       if not row then
 		  break