我已经构建了一个基于插件的应用程序,其中“插件”(python 模块)可以由 imp 加载,然后由 APScheduler 安排稍后执行,我能够成功集成它们,但我想在崩溃或应用程序重新启动的情况下实现持久性,所以我将默认内存作业存储更改为 SqlAlchemyJobStore,它在您第一次执行程序时运行良好:任务被加载、调度、保存在数据库中并在正确的时间执行。
问题是当我尝试再次加载应用程序时,我得到了这个回溯:
ERROR:apscheduler.jobstores.default:Unable to restore job "d3e0f0068df54d15986e9b7b6757f665" -- removing it
Traceback (most recent call last):
File "/home/jesus/.local/lib/python2.7/site-packages/apscheduler/jobstores/sqlalchemy.py", line 126, in _get_jobs
jobs.append(self._reconstitute_job(row.job_state))
File "/home/jesus/.local/lib/python2.7/site-packages/apscheduler/jobstores/sqlalchemy.py", line 114, in _reconstitute_job
job.__setstate__(job_state)
File "/home/jesus/.local/lib/python2.7/site-packages/apscheduler/job.py", line 228, in __setstate__
self.func = ref_to_obj(self.func_ref)
File "/home/jesus/.local/lib/python2.7/site-packages/apscheduler/util.py", line 257, in ref_to_obj
raise LookupError('Error resolving reference %s: could not import module' % ref)
LookupError: Error resolving reference __init__:run: could not import module
所以很明显,再次尝试导入函数时出现问题
这是我的调度程序初始化:
executors = {'default': ThreadPoolExecutor(5)}
jobstores = {'default': SQLAlchemyJobStore(url='sqlite:///jobs.sqlite')}
self.scheduler = BackgroundScheduler(executors = executors,jobstores=jobstores)
我有一个“测试”字典,其中包含应该加载的“插件”和一些参数,“load_plugin”使用 imp 按其名称加载插件。
for test,parameters in tests.items():
if test in pluggins:
module=load_plugin(pluggins[test])
self.jobs[test]=self.scheduler.add_job(module.run,"interval",seconds=parameters["interval"],name=test)
关于如何处理重组工作的任何想法?