[web2py] Re: Sending email from background queue

2012-08-13 Thread Florian Letsch
I've accidentally posted this twice. Please have a look at the other 
thread: 
https://groups.google.com/forum/?fromgroups#!topic/web2py/u5R-vGcP580%5B1-25%5D
I answered your question there (emails are added from within the 
application).

On Sunday, 12 August 2012 06:17:15 UTC+12, Anthony wrote:

 How are emails added to the database -- does that happen within the 
 application, or also in a script?

 On Saturday, August 11, 2012 12:55:40 AM UTC-4, Florian Letsch wrote:

 *My first post somehow didn't make it to the group, I don't know where 
 it got lost. Sorry if I submit this twice, I have never participated in a 
 news group before.*

 I am trying to set up a background queue for sending email as described 
 in the web2py book. 
 http://web2py.com/books/default/chapter/29/8#Sending-messages-using-a-background-task

 However, emails are only sent when they have been in the database before 
 starting the script. Emails I add to the database when the queue is running 
 do not get picked up for some reason. I got it to work by adding an 
 additional db.commit() before the select() in every loop run. I assume this 
 should not be needed. Does anyone have an idea why this is not working 
 without that additional commit?

 import time
 while True: 
 db.commit() # not working without this line 
 rows = db(db.queue.status=='pending').select()
 for row in rows:
 if mail.send(to=row.email,
 subject=row.subject,
 message=row.message):
 row.update_record(status='sent')
 else:
 row.update_record(status='failed')
 db.commit()
 time.sleep(60) # check every minute




-- 





[web2py] Re: Sending email from background queue

2012-08-11 Thread Anthony
How are emails added to the database -- does that happen within the 
application, or also in a script?

On Saturday, August 11, 2012 12:55:40 AM UTC-4, Florian Letsch wrote:

 *My first post somehow didn't make it to the group, I don't know where it 
 got lost. Sorry if I submit this twice, I have never participated in a news 
 group before.*

 I am trying to set up a background queue for sending email as described in 
 the web2py book. 
 http://web2py.com/books/default/chapter/29/8#Sending-messages-using-a-background-task

 However, emails are only sent when they have been in the database before 
 starting the script. Emails I add to the database when the queue is running 
 do not get picked up for some reason. I got it to work by adding an 
 additional db.commit() before the select() in every loop run. I assume this 
 should not be needed. Does anyone have an idea why this is not working 
 without that additional commit?

 import time
 while True: 
 db.commit() # not working without this line 
 rows = db(db.queue.status=='pending').select()
 for row in rows:
 if mail.send(to=row.email,
 subject=row.subject,
 message=row.message):
 row.update_record(status='sent')
 else:
 row.update_record(status='failed')
 db.commit()
 time.sleep(60) # check every minute




--