不確定如何在數據庫上存儲作業。每當我跑我的瓶的應用程序運行的第一次,然後當我關閉服務器並重新啓動應用程序,我得到的錯誤:Flask_APScheduler衝突的作業錯誤?
sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) UNIQUE constraint failed: apscheduler_jobs.id [SQL: 'INSERT INTO apscheduler_jobs (id, next_run_time, job_state) VALUES (?, ?, ?)'] [parameters: ('job1', 1505488120.453826, <memory at 0x00000200DB4A6DC8>)]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "run.py", line 4, in <module>
scheduler.start()
File "C:\Anaconda3\envs\g2x_flask\lib\site-packages\flask_apscheduler\scheduler.py", line 82, in start
self._scheduler.start()
File "C:\Anaconda3\envs\g2x_flask\lib\site-packages\apscheduler\schedulers\background.py", line 33, in start
BaseScheduler.start(self, *args, **kwargs)
File "C:\Anaconda3\envs\g2x_flask\lib\site-packages\apscheduler\schedulers\base.py", line 154, in start
self._real_add_job(job, jobstore_alias, replace_existing)
File "C:\Anaconda3\envs\g2x_flask\lib\site-packages\apscheduler\schedulers\base.py", line 851, in _real_add_job
store.add_job(job)
File "C:\Anaconda3\envs\g2x_flask\lib\site-packages\apscheduler\jobstores\sqlalchemy.py", line 94, in add_job
raise ConflictingIdError(job.id)
apscheduler.jobstores.base.ConflictingIdError: 'Job identifier (job1) conflicts with an existing job'
我app\__intel__.py
文件看起來像:
from flask import Flask
from flask_apscheduler import APScheduler
from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore
from .models import db
app = Flask(__name__)
app.config.from_object('config.BaseConfig')
db.init_app(app)
class APSConfig(object):
JOBS = [
{
'id': 'job1',
'func': 'intel_app.jobs:job1',
'args': (1, 2),
'trigger': 'interval',
'seconds': 10
}
]
SCHEDULER_JOBSTORES = {
'default': SQLAlchemyJobStore(url=app.config['SQLALCHEMY_DATABASE_URI'])
}
SCHEDULER_EXECUTORS = {
'default': {'type': 'threadpool', 'max_workers': 20}
}
SCHEDULER_JOB_DEFAULTS = {
'coalesce': False,
'max_instances': 3
}
SCHEDULER_API_ENABLED = True
app.config.from_object(APSConfig())
scheduler = APScheduler()
scheduler.init_app(app)
它看起來像每次應用程序啓動時,它都會嘗試使用相同的jobid重新創建作業,但是,我不確定如何才能讓它只創建一次作業,然後如果作業在數據庫中使用它。
編輯:我的最終目標是要起牀,從一個網站提取數據的作業,然後在數據庫中存儲的數據。所以,我想將這項工作設置爲cron工作並將其部署到heroku上。