I have basically the following code (I simplified it a bunch):
while True:
new_payments = session.query(PayPalPayments) \
.filter_by(status='new') \
.order_by(PayPalPayments.payment_id) \
.all()
process_payments(new_payments)
time.sleep(30)
开发者_如何学Go
For some reason only the first time I run the program the query returns new_payments
. If a new payment comes in while the program is time.sleep(30)
sleeping, then the query doesn't return any new results.
Are the query results cached for the same query in SqlAlchemy? Any ideas how to make each query to really query the database and return new rows?
If you are using automatic transactions, I think you need to commit the transaction to force SQLAlchemy to refresh the results.
Try this:
while True:
new_payments = session.query(PayPalPayments) \
.filter_by(status='new') \
.order_by(PayPalPayments.payment_id) \
.all()
process_payments(new_payments)
session.commit()
time.sleep(30)
精彩评论