Suggested addition to http://docs.turbogears.org/1.0/Scheduler (and later versions too?)
-------- The scheduler example is trivial, and does not deal with the real- world case where your scheduled job interacts with the database. In practice, each time the scheduled job runs it can and likely will create another connection to the database, until the app fails on a 'too many open files error'. The solution is hinted at in this page:http://docs.turbogears.org/1.0/ModelOutsideTG, but here is some additional information you may find useful. How to set up a scheduled recurring job in jobs.py: def schedule(): #now add jobs to the schedule #the schedule is activated in controllers.py #interval 300 seconds = 5 minutes add_interval_task(action=fetch_the_mail, taskname="fetch_the_mail", initialdelay=30,interval=300) Define your task, and use hub.commit() to finalise the transaction with the database: from <packagename> import model # define the scheduled job def fetch_the_mail(): mailboxes = model.MailboxInfo.select() for box in mailboxes: user = "[EMAIL PROTECTED]" % (box.userid,box.server) password = box.passwd serverName = box.mailbox serverInfo = [serverName,user,password] f = FetchSpot() spotInfo = f.parse_mail(serverInfo) if spotInfo != []: #then we have new information for info in spotInfo: msgType,num,lati,longi,msgTime,creator = info s = model.SpotInfo.byUnit_number(num) model.MessageInfo(messageType=msgType,unit_number=num,owner=s, latitude=lati,longitude=longi,messageTime=msgTime,creator=creator) #important! commit your database changes model.hub.commit() When you run your app, find the PID of the Turbogears app: ps aux | grep start-<packagename>.py (replace <packagename> with your own project's name) Then check the number of open files with: 'cat /proc/<pid>/fds'. The proc filesystem is not available at all in Windows, nor by default in Mac OS X (but read up on MacFuse and you should find instructions on how to install it). You should see something like this: cat /proc/33598/fds 0 vnode /dev/ttys002 1 vnode /dev/ttys002 2 vnode /dev/ttys002 3 socket SOCK_STREAM, ip, AF_UNIX 6 vnode /Library/WebServer/Documents/SpotPlot/ devdata.sqlite 7 vnode /Library/WebServer/Documents/SpotPlot/ devdata.sqlite Monitor your application to ensure that the number of the connections to your database does not increase each time your scheduled job is run. --------- Hope this helps, S --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears Docs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/turbogears-docs?hl=en -~----------~----~----~----~------~----~------~--~---
