1
我試圖使用APS的MongoJobStore
example。示例代碼是:APScheduler作業未重新啓動後運行
import logging
import os
import sys
from datetime import datetime, timedelta
from apscheduler.schedulers.blocking import BlockingScheduler
logging.basicConfig()
def alarm(time):
print('Alarm! This alarm was scheduled at %s.' % time)
if __name__ == '__main__':
scheduler = BlockingScheduler()
scheduler.add_jobstore('mongodb', collection='example_jobs', host='192.168.0.108', port=27017)
if len(sys.argv) > 1 and sys.argv[1] == '--clear':
scheduler.remove_all_jobs()
alarm_time = datetime.now() + timedelta(seconds=10)
# scheduler.add_job(alarm, 'date', run_date=alarm_time, args=[datetime.now()], id="la")
print('To clear the alarms, run this example with the --clear argument.')
print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
scheduler.start()
首先測試我跑的代碼和alarm
方法的輸出得到了印刷在控制檯上。然後爲了測試mongo的使用,我做了以下操作:
- 運行示例並在執行作業之前停止它。
這創造了分貝
> db.example_jobs.find().pretty() { "_id" : "la", "next_run_time" : 1456771825.792437, "job_state" : BinData(0,"gAJ9cQEoVQRhcmdzcQJjZGF0ZXRpbWUKZGF0ZXRpbWUKcQNVCgfgAwEAFA8MF4SFUnEEhXEFVQhleGVjdXRvcnEGVQdkZWZhdWx0cQdVDW1heF9pbnN0YW5jZXNxCEsBVQRmdW5jcQlVDl9fbWFpbl9fOmFsYXJtcQpVAmlkcQtVAmxhcQxVDW5leHRfcnVuX3RpbWVxDWgDVQoH4AMBABQZDBd1Y3B5dHoKX3AKcQ4oVQxBc2lhL0tvbGthdGFxD01YTUsAVQNJU1RxEHRScRGGUnESVQRuYW1lcRNVBWFsYXJtcRRVEm1pc2ZpcmVfZ3JhY2VfdGltZXEVSwFVB3RyaWdnZXJxFmNhcHNjaGVkdWxlci50cmlnZ2Vycy5kYXRlCkRhdGVUcmlnZ2VyCnEXKYFxGH1xGX1xGlUIcnVuX2RhdGVxG2gSc4ZiVQhjb2FsZXNjZXEciFUHdmVyc2lvbnEdSwFVBmt3YXJnc3EefXEfdS4=") }
然後我評論說這是添加任務就行了以下項:
# scheduler.add_job(alarm, 'date', run_date=alarm_time, args=[datetime.now()], id="la")
然後我再次運行腳本,並得到了以下的輸出:
To clear the alarms, run this example with the --clear argument. Press Ctrl+C to exit WARNING:apscheduler.executors.default:Run time of job "alarm (trigger: date[2016-03-01 00:35:27 IST], next run at: 2016-03-01 00:35:27 IST)" was missed by 0:00:19.290825
alarm
函數的輸出未打印,記錄被刪除從數據庫。
我試着調試第二次運行,代碼讀取來自數據庫的工作,然後將其提交給threadpool
。但是沒有輸出被打印。
爲什麼會發生這種情況?
請問你是如何設置默認記錄器的?我無法弄清楚,並總是提示消息,如'無法找到記錄器apscheduler.executors.default'。 – FaithReaper