-
We use async def get_async_session() -> AsyncSession:
async_session = sessionmaker(
engine, class_=AsyncSession, expire_on_commit=False
)
async with async_session() as session:
yield session and each @router.post(
"/signup",
status_code=status.HTTP_201_CREATED,
)
async def signup_user(
request: SignupRequest,
session: AsyncSession = Depends(get_async_session)
) -> SignupResponse:
# Try and get a user by email
user = await User.get_by_email(session, request.email)
if user:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="User already exists"
)
user = await User.create(session, **request.dict()) Since My from sqlalchemy.ext.asyncio import AsyncSession
from taskiq_dependencies import Depends
@broker.task
async def send_account_verification_email(
user_id: str,
session: AsyncSession = Depends(get_async_session)
) -> None:
user = await User.get(session, user_id)
import logging
logging.error("===================")
logging.error(session)
logging.error(user_id)
logging.error(user)
logging.error("===================") which tells me that
I am wondering if anyone can throw some light on what I might have missed in using
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I guess, that problem is because now tasks resolved after startup. Since taskiq calculates all dependency graphs on startup, we need to know about all tasks before the startup event. To solve your problem, you can either use taskiq worker app.tkq:broker app.tasks Or taskiq worker app.tkq:broker --fs-discover All tasks imported like this become available to broker before startup events and it will calculate all dependency graphs for it. You can get more information about how to automatic task importing here: https://taskiq-python.github.io/guide/cli.html#auto-importing. |
Beta Was this translation helpful? Give feedback.
I guess, that problem is because now tasks resolved after startup.
Before the release https://github.com/taskiq-python/taskiq-fastapi/releases/tag/0.3.0 taskiq-fastapi was resolving all tasks, used by an application before startup. Now it does it during the startup. Because this behavior was causing bugs, when application uses multiple brokers.
Since taskiq calculates all dependency graphs on startup, we need to know about all tasks before the startup event. To solve your problem, you can either use
--fs-discover
parameter, or add modules with your tasks directly to worker command.Or
All tasks imported like…