简体   繁体   English

Python实时忙查询数据库

[英]Python Real-time Busy Polling a Database

I have a database table that gets row/record INSERTS from a third-party application. 我有得到行/记录数据库表INSERTS从第三方应用程序。 This table has one column labeled 'active' that is always False when each new record is INSERTED by the third-party application. 该表具有标记为“活动”的一列,当第三方应用程序插入每个新记录时,该列始终为False

My application needs to read rows on that database table, and find those rows that have the 'active' column with a Boolean value of False and then UPDATE the column to True (after doing some processing on the row). 我的应用程序需要读取该数据库表上的行,并找到带有布尔值False的“活动”列的那些行,然后将该列更新为True (在对该行进行一些处理之后)。

What is the best way to do this? 做这个的最好方式是什么? Right now I just have a simple while loop that repeatedly queries the database and processes that table. 现在,我只有一个简单的while循环,该循环重复查询数据库并处理该表。 But I think there must be a better way. 但是我认为必须有更好的方法。

My question is: What is the proper way to busy-poll a database in Python so that my application notices changes to the DB as soon as possible? 我的问题是:用Python忙轮询数据库以使我的应用程序尽快注意到数据库更改的正确方法是什么?

I think you should consider doing a trigger in the DB that fires of a script to you application, instead of polling the DB. 我认为您应该考虑在数据库中执行向您的应用程序触发脚本的触发器,而不是轮询数据库。

This would probably best be done with the help of PL/sh 最好在PL / sh的帮助下完成此操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM