Skip to content

Commit

Permalink
Minor refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
cmin764 committed Nov 23, 2024
1 parent 9387fde commit 823718f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion deep_ice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async def lifespan(fast_app: FastAPI):
class TaskQueue:
functions = [payment_service.make_payment_task]
redis_settings = redis_settings
max_tries = settings.TASK_MAX_RETRIES
max_tries = settings.TASK_MAX_TRIES
retry_delay = settings.TASK_RETRY_DELAY


Expand Down
6 changes: 3 additions & 3 deletions deep_ice/api/routes/cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ async def get_cart_items(current_user: CurrentUserDep, cart_service: CartService
return cart


@router.post("/items", response_model=RetrieveCartItem)
@router.post(
"/items", response_model=RetrieveCartItem, status_code=status.HTTP_201_CREATED
)
async def add_item_to_cart(
session: SessionDep,
current_user: CurrentUserDep,
cart_service: CartServiceDep,
item: Annotated[CreateCartItem, Body()],
response: Response,
):
cart = await cart_service.ensure_cart(cast(int, current_user.id))
cart_item = CartItem(cart_id=cart.id, **item.model_dump())
Expand All @@ -65,7 +66,6 @@ async def add_item_to_cart(
else:
cart_item.icecream = icecream

response.status_code = status.HTTP_201_CREATED
return cart_item


Expand Down
5 changes: 2 additions & 3 deletions deep_ice/api/routes/payments.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
from sqlalchemy.exc import SQLAlchemyError

from deep_ice.core import logger
from deep_ice.core.dependencies import CurrentUserDep, SessionDep
from deep_ice.core.dependencies import CartServiceDep, CurrentUserDep, SessionDep
from deep_ice.models import PaymentMethod, PaymentStatus, RetrievePayment
from deep_ice.services.cart import CartService
from deep_ice.services.order import OrderService
from deep_ice.services.payment import PaymentError, PaymentService, payment_stub
from deep_ice.services.stats import stats_service
Expand All @@ -20,13 +19,13 @@
async def make_payment(
session: SessionDep,
current_user: CurrentUserDep,
cart_service: CartServiceDep,
method: Annotated[PaymentMethod, Body(embed=True)],
request: Request,
response: Response,
):
# FIXME(cmin764): Check if we need an async Lock primitive here in order to allow
# only one user to submit an order at a time. (based on available stock check)
cart_service = CartService(session)
cart = await cart_service.get_cart(cast(int, current_user.id))
if not cart or not cart.items:
raise HTTPException(
Expand Down
2 changes: 1 addition & 1 deletion deep_ice/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Settings(BaseSettings):

REDIS_HOST: str = "localhost"

TASK_MAX_RETRIES: int = 3
TASK_MAX_TRIES: int = 3
TASK_RETRY_DELAY: int = 1 # seconds between retries
TASK_BACKOFF_FACTOR: int = 5 # seconds to wait based on the job try counter

Expand Down

0 comments on commit 823718f

Please sign in to comment.