APScheduler如何将作业保存在数据库中?(Python)

2024-10-02 22:30:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图弄清楚在我使用高级Python调度器保存一些作业后,sqlite数据库的模式是什么样子的。我需要它是因为我想在UI中显示作业。我试着写一个简单的脚本来保存一份工作:

from pytz import utc

from apscheduler.schedulers.background import BackgroundScheduler

from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore
from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor
from datetime import datetime
import os

from apscheduler.schedulers.blocking import BlockingScheduler

jobstores = {

    'default': SQLAlchemyJobStore(url='sqlite:///test.db')
}
executors = {
    'default': ThreadPoolExecutor(20),
    'processpool': ProcessPoolExecutor(5)
}
job_defaults = {
    'coalesce': False,
    'max_instances': 3
}
scheduler = BackgroundScheduler(jobstores=jobstores, executors=executors, job_defaults=job_defaults, timezone=utc)


def tick():
    print('Tick! The time is: %s' % datetime.now())



scheduler = BlockingScheduler()
scheduler.add_executor('processpool')
scheduler.add_job(tick, 'interval', seconds=3)
print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))

try:
    scheduler.start()
except (keyboardInterrupt, SystemExit):
    pass

但是终端中的“.fullschema”命令显示,在测试数据库. 我到底做错了什么?在


Tags: fromimport数据库sqlitedatetime作业jobscheduler