[英]Run multiple schedule jobs at same time using Python Schedule
我在 python 中使用cx Oracle
和schedule
模塊。以下是偽代碼。
import schedule,cx_Oracle
def db_operation(query):
'''
Some DB operations like
1. Get connection
2. Execute query
3. commit result (in case of DML operations)
'''
schedule.every().hour.at(":10").do(db_operation,query='some_query_1') # Runs at 10th minute in every hour
schedule.every().day.at("13:10").do(db_operation,query='some_query_2') # Runs at 1:10 p.m every day
上面的兩個scheduled jobs calls the same function
(它執行一些數據庫操作)並且將在 13:10 重合。
問題:
priority of first job over second
,該怎么做?only one of these should be accessing the database
,否則可能導致數據不一致。 如何處理這種情況? 比如在訪問 function 時是否可以加鎖,或者應該以某種方式鎖定表?我看了一下 schedule 的代碼,得出以下結論:
some_query_1
將在some_query_2
之前執行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.