agronholm / agronholm/apscheduler

SQLAlchemyJobStore with AsyncIOScheduler and FastAPI gives OperationalError

Đang mở
#499 15 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
7.6k
Fork
783
Merge trung bình
4 ngày 8 giờ
Pull request đã merge (30 ngày)
5

Mô tả

**Describe the bug**
When reloading the fastapi process on Heroku, I get an OperationalError described as following:

```
2021-03-06 12:30:29,625 ERROR red_circle
From fastapi:load_schedule_or_create_blank
(sqlite3.OperationalError) table apscheduler_jobs already exists
[SQL:
CREATE TABLE apscheduler_jobs (
id VARCHAR(191) NOT NULL,
next_run_time FLOAT,
job_state BLOB NOT NULL,
PRIMARY KEY (id)
)

]
(Background on this error at: http://sqlalche.me/e/13/e3q8)
```

**To Reproduce**
Please provide a **minimal** reproducible example that developers can run to investigate the problem.
You can find help for creating such an example [here](https://stackoverflow.com/help/minimal-reproducible-example).
I'm loading the scheduler on a fastapi web service:

```
@router.on_event("startup")
async def load_schedule_or_create_blank():
"""

Initialize the Schedule Object as a Global Param and also load existing Schedules from SQLite
This allows for persistent schedules across server restarts.
:return:
"""
global Scheduler
try:
jobstores = {
'default': SQLAlchemyJobStore(url='sqlite:///aps_scheduler_jobs.sqlite')
}
Scheduler = AsyncIOScheduler(jobstores=jobstores)
Scheduler.start()
Scheduler.add_listener(my_listener, EVENT_JOB_ERROR)
logger.info("Created Schedule Object")
except Exception as e:
logger.exception(str(e))
logger.error("Unable to Create Schedule Object")
```

**Expected behavior**
It shoudln't give this error. This also results in not adding jobs or misfiring them.

**Additional context**
Can this be connected to the async function declared?

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.