amisadmin / fastapi-scheduler

FastAPI-Scheduler is a simple scheduled task management FastAPI extension based on APScheduler.
82 stars 13 forks source link

Occurs an error and does not work. #11

Open Yangeok opened 2 months ago

Yangeok commented 2 months ago

I installed the necessary packages and copied and executed the script provided as an example, but encountered an error.

Below is stack trace:

INFO:     Will watch for changes in these directories: ['/Users/***']
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     Started reloader process [92055] using StatReload
INFO:     Started server process [92059]
INFO:     Waiting for application startup.
ERROR:    Traceback (most recent call last):
  File "/Users/***/.venv/lib/python3.12/site-packages/starlette/routing.py", line 686, in lifespan
    async with self.lifespan_context(app) as maybe_state:
  File "/Users/***/.venv/lib/python3.12/site-packages/starlette/routing.py", line 575, in __aenter__
    await self._router.startup()
  File "/Users/***/.venv/lib/python3.12/site-packages/starlette/routing.py", line 663, in startup
    await handler()
  File "/Users/***/src/main.py", line 33, in startup
    site.mount_app(app)
  File "/Users/***/.venv/lib/python3.12/site-packages/fastapi_amis_admin/admin/admin.py", line 1541, in mount_app
    fastapi.add_middleware(BaseHTTPMiddleware, dispatch=self.db.asgi_dispatch)
  File "/Users/***/.venv/lib/python3.12/site-packages/starlette/applications.py", line 139, in add_middleware
    raise RuntimeError("Cannot add middleware after an application has started")
RuntimeError: Cannot add middleware after an application has started

ERROR:    Application startup failed. Exiting.

Need help. How can I resolve this problem?

guofei1989 commented 1 month ago

You can refer to : https://github.com/amisadmin/fastapi-scheduler/issues/7