[web2py] Re: Sending emails with background queue problem
The problem sums up to: I expect when committing that something like saving a file happens...everybody, and I mean everybody trying to access that file later would read the same thing. SQlite, MSSQL, Postgresql, Oracle adapters work this way, and I assume also mongo and couchdb. I tried to read the PEP for the DBAPI and saw no explicit references to what committing should do in reference to a multiprocess environment (i.e. if commit should save the changes and make them available for other processes). However, I'm not a python guru to rule that out, I'm just saying that from a DAL point of view having to commit before reading to see records changed/inserted by other processes is required ONLY from mysql. On Tuesday, August 14, 2012 6:15:14 AM UTC+2, Massimo Di Pierro wrote: Should we change the settings in the Adapter? On Monday, 13 August 2012 17:21:09 UTC-5, Niphlod wrote: The most probable cause is the transaction isolation problem with mysql as explained in https://groups.google.com/d/msg/web2py/qLHP3iYz8Lo/Ly2wqK4qZZgJ I'm starting to think that it's the only adapter behaving differently. On Monday, August 13, 2012 11:46:11 PM UTC+2, Florian Letsch wrote: Yes, I am using mysql. I've accidentally posted this twice [0] on the group (sorry for that). Anthony asked: How are emails added to the database -- does that happen within the application, or also in a script? Emails are added to the database from within the application (a controller function adds a confirmation email to the queue) [0] https://groups.google.com/forum/?fromgroups#!topic/web2py/YT2jDMea6lU On Sunday, 12 August 2012 07:17:39 UTC+12, Massimo Di Pierro wrote: Are you using mysql? On Friday, 10 August 2012 23:11:03 UTC-5, Florian Letsch wrote: I want to send emails using a background queue as described in the web2py book: http://web2py.com/books/default/chapter/29/8#Sending-messages-using-a-background-task However, the queue only sends emails that have been in the database when I start the script. Database entries added lateron don't get picked up by the script. The only way I can achieve that is to add another db.commit() before the select(). I am sure this is not supposed to be necessary. Does anyone know why this is happening? import time while True: db.commit() # Only works if I add 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 emails with background queue problem
Yes, I am using mysql. I've accidentally posted this twice [0] on the group (sorry for that). Anthony asked: How are emails added to the database -- does that happen within the application, or also in a script? Emails are added to the database from within the application (a controller function adds a confirmation email to the queue) [0] https://groups.google.com/forum/?fromgroups#!topic/web2py/YT2jDMea6lU On Sunday, 12 August 2012 07:17:39 UTC+12, Massimo Di Pierro wrote: Are you using mysql? On Friday, 10 August 2012 23:11:03 UTC-5, Florian Letsch wrote: I want to send emails using a background queue as described in the web2py book: http://web2py.com/books/default/chapter/29/8#Sending-messages-using-a-background-task However, the queue only sends emails that have been in the database when I start the script. Database entries added lateron don't get picked up by the script. The only way I can achieve that is to add another db.commit() before the select(). I am sure this is not supposed to be necessary. Does anyone know why this is happening? import time while True: db.commit() # Only works if I add 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 emails with background queue problem
The most probable cause is the transaction isolation problem with mysql as explained in https://groups.google.com/d/msg/web2py/qLHP3iYz8Lo/Ly2wqK4qZZgJ I'm starting to think that it's the only adapter behaving differently. On Monday, August 13, 2012 11:46:11 PM UTC+2, Florian Letsch wrote: Yes, I am using mysql. I've accidentally posted this twice [0] on the group (sorry for that). Anthony asked: How are emails added to the database -- does that happen within the application, or also in a script? Emails are added to the database from within the application (a controller function adds a confirmation email to the queue) [0] https://groups.google.com/forum/?fromgroups#!topic/web2py/YT2jDMea6lU On Sunday, 12 August 2012 07:17:39 UTC+12, Massimo Di Pierro wrote: Are you using mysql? On Friday, 10 August 2012 23:11:03 UTC-5, Florian Letsch wrote: I want to send emails using a background queue as described in the web2py book: http://web2py.com/books/default/chapter/29/8#Sending-messages-using-a-background-task However, the queue only sends emails that have been in the database when I start the script. Database entries added lateron don't get picked up by the script. The only way I can achieve that is to add another db.commit() before the select(). I am sure this is not supposed to be necessary. Does anyone know why this is happening? import time while True: db.commit() # Only works if I add 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 emails with background queue problem
Should we change the settings in the Adapter? On Monday, 13 August 2012 17:21:09 UTC-5, Niphlod wrote: The most probable cause is the transaction isolation problem with mysql as explained in https://groups.google.com/d/msg/web2py/qLHP3iYz8Lo/Ly2wqK4qZZgJ I'm starting to think that it's the only adapter behaving differently. On Monday, August 13, 2012 11:46:11 PM UTC+2, Florian Letsch wrote: Yes, I am using mysql. I've accidentally posted this twice [0] on the group (sorry for that). Anthony asked: How are emails added to the database -- does that happen within the application, or also in a script? Emails are added to the database from within the application (a controller function adds a confirmation email to the queue) [0] https://groups.google.com/forum/?fromgroups#!topic/web2py/YT2jDMea6lU On Sunday, 12 August 2012 07:17:39 UTC+12, Massimo Di Pierro wrote: Are you using mysql? On Friday, 10 August 2012 23:11:03 UTC-5, Florian Letsch wrote: I want to send emails using a background queue as described in the web2py book: http://web2py.com/books/default/chapter/29/8#Sending-messages-using-a-background-task However, the queue only sends emails that have been in the database when I start the script. Database entries added lateron don't get picked up by the script. The only way I can achieve that is to add another db.commit() before the select(). I am sure this is not supposed to be necessary. Does anyone know why this is happening? import time while True: db.commit() # Only works if I add 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 emails with background queue problem
Are you using mysql? On Friday, 10 August 2012 23:11:03 UTC-5, Florian Letsch wrote: I want to send emails using a background queue as described in the web2py book: http://web2py.com/books/default/chapter/29/8#Sending-messages-using-a-background-task However, the queue only sends emails that have been in the database when I start the script. Database entries added lateron don't get picked up by the script. The only way I can achieve that is to add another db.commit() before the select(). I am sure this is not supposed to be necessary. Does anyone know why this is happening? import time while True: db.commit() # Only works if I add 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 --