agronholm / agronholm/apscheduler
SQLAlchemyJobStore with AsyncIOScheduler and FastAPI gives OperationalError
- Vorherrschende Sprache
- Python
- Sterne
- 7.6k
- Forks
- 783
- Ø Merge
- 4 T. 8 Std.
- Gemergte PRs (30 T.)
- 5
Beschreibung
**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?
Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.