github中介紹
Advanced Python Scheduler (APScheduler) is a Python library that lets you schedule your Python code to be executed later, either just once or (高級python調(diào)度器是一個python庫,它可以調(diào)度python代碼延遲運行,運行一次,定期運行,簡稱為apscheduler,) periodically. You can add new jobs or remove old ones on the fly as you please. If you store your jobs in a database, they will also survive scheduler (你可以在匆忙中按照自己情況添加新的任務(wù)或者刪除之前的任務(wù),如果你將任務(wù)存儲在數(shù)據(jù)庫中,調(diào)度器將會重啟這些任務(wù)并且保持運行任務(wù)狀態(tài),) restarts and maintain their state. When the scheduler is restarted, it will then run all the jobs it should have run while it was offline
概述
APScheduler 是由python 實現(xiàn)的一個輕量級任務(wù)調(diào)度器,可以按照一定的間隔intervalTrigger,指定時間的形式觸發(fā)待執(zhí)行的任務(wù)(即調(diào)用函數(shù)或者調(diào)用python 的callable對象)
模塊組織
scheduler調(diào)度器的核心部分,負(fù)責(zé)對job的管理和調(diào)度,用戶使用添加任務(wù),移除任務(wù),啟動調(diào)度器都會通過scheduler提供的接口完成 job 封裝了需要調(diào)度的任務(wù),每一個job實例是在scheduler添加job時候被初始化,具體的初始化參數(shù)決定了調(diào)度被觸發(fā)的形式(3類不同的trigger) trigger包含simpletrigger,intervaltrigger 和crontrigger三個類,trigger的作用就是計算下一次觸發(fā)任務(wù)的時間 jobstore抽象基類,針對任務(wù)存儲的介質(zhì)有多個實現(xiàn),包括基于內(nèi)存ramjobstore,使用shelve的簡單持久化存儲shelvejobstore,使用數(shù)據(jù)庫存儲redisjobstore,mongodbjobstore等,如果不指定參數(shù)默認(rèn)使用ramjobstore,使用持久化的jobstore的目的是在scheduler重啟之后能夠恢復(fù)原有的任務(wù)調(diào)度