在我的项目代码中。我Django 1.11
和APScheduler 3.3.1
与Postgres 9.6
问题出在完整的测试期间。在Django完成迁移之前,APScheduler
命中数据库Postgres
。
在我的OSX笔记本电脑上没有这个问题。
有什么技巧可以避免这个问题吗?
models.py
from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore
from apscheduler.schedulers.background import BackgroundScheduler
schd_inst = BackgroundScheduler(jobstores={
'default': SQLAlchemyJobStore(
url=settings.DATABASE_URL,
tablename='apscheduler_jobs'
)
})
try:
schd_inst.start()
except SchedulerAlreadyRunningError:
logger.info(str(SchedulerAlreadyRunningError))
class MailAPIScheduler(DirtyFieldsMixin, AbstractSoftModelController):
dealer = models.ForeignKey(Dealer, on_delete=models.CASCADE)
api_url = models.URLField()
schedule_time = JSONField(default={'hour': 0, 'minute': 0}) # 24hr e.g. {'hour': 13, 'minute': 3}
parameters = JSONField() # {'key': 'api-key', 'value': '123'}
summary_email_receivers = ArrayField(
models.EmailField(blank=True),
blank=True
)
schd_id = models.UUIDField(default=uuid.uuid4, unique=True) # uuid gen at python code not database level
settings.py
LOCAL_APPS = [
...,
'myapp',
...
]
错误:
python manage.py test
Scheduler DB: postgres://postgres:qwerty@postgres:5432/eneos_pos
Hey, I'm Local!
Scheduler DB: postgres://postgres:qwerty@postgres:5432/eneos_pos
Traceback (most recent call last):
...
psycopg2.OperationalError: FATAL: database "eneos_pos" does not exist
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
...
File "/usr/local/lib/python3.6/site-packages/psycopg2/__init__.py", line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) FATAL: database "eneos_pos" does not exist
FAILEDBuild failed !!!.