jonra1993 / fastapi-alembic-sqlmodel-async

This is a project template which uses FastAPI, Pydantic 2.0, Alembic and async SQLModel as ORM. It shows a complete async CRUD using authentication and role base access control.
MIT License
878 stars 142 forks source link

celery beat is not going in correct table #77

Closed bazylhorsey closed 11 months ago

bazylhorsey commented 11 months ago

In my testing, it seems all the celery beat data is not going in the celery beat table, instead its going in the postgres database.

jonra1993 commented 11 months ago

Hello @bazylhorsey that is weird can you check that DATABASE_CELERY_NAME environment variable is set correctly

.env file

...........
#############################################
# PostgreSQL database environment variables
#############################################
DATABASE_HOST=database
DATABASE_USER=postgres
DATABASE_PASSWORD=postgres
DATABASE_NAME=fastapi_db
DATABASE_CELERY_NAME=celery_schedule_jobs
DATABASE_PORT=5432
........................

config.py file

..........
    @validator("SYNC_CELERY_BEAT_DATABASE_URI", pre=True)
    def assemble_celery_beat_db_connection(
        cls, v: str | None, values: dict[str, Any]
    ) -> Any:
        if isinstance(v, str):
            return v
        return PostgresDsn.build(
            scheme="postgresql+psycopg2",
            user=values.get("DATABASE_USER"),
            password=values.get("DATABASE_PASSWORD"),
            host=values.get("DATABASE_HOST"),
            port=str(values.get("DATABASE_PORT")),
            path=f"/{values.get('DATABASE_CELERY_NAME') or ''}",
        )

    ASYNC_CELERY_BEAT_DATABASE_URI: str | None

    @validator("ASYNC_CELERY_BEAT_DATABASE_URI", pre=True)
    def assemble_async_celery_beat_db_connection(
        cls, v: str | None, values: dict[str, Any]
    ) -> Any:
        if isinstance(v, str):
            return v
        return PostgresDsn.build(
            scheme="postgresql+asyncpg",
            user=values.get("DATABASE_USER"),
            password=values.get("DATABASE_PASSWORD"),
            host=values.get("DATABASE_HOST"),
            port=str(values.get("DATABASE_PORT")),
            path=f"/{values.get('DATABASE_CELERY_NAME') or ''}",
        )
..........

As you can see to create the celery link it uses the same database engine but DATABASE_CELERY_NAME defines that it is a different database.

Can you please share a screenshot of what you see?