Coverage for polar/checkout/tasks.py: 46%
24 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 12:42 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 12:42 +0000
1import uuid
3from polar.exceptions import PolarTaskError
4from polar.worker import AsyncSessionMaker, CronTrigger, TaskPriority, actor
6from .repository import CheckoutRepository
7from .service import checkout as checkout_service
10class CheckoutTaskError(PolarTaskError): ... 10 ↛ 13line 10 didn't jump to line 13 because
13class CheckoutDoesNotExist(CheckoutTaskError):
14 def __init__(self, checkout_id: uuid.UUID) -> None:
15 self.checkout_id = checkout_id
16 message = f"The checkout with id {checkout_id} does not exist."
17 super().__init__(message)
20@actor(actor_name="checkout.handle_free_success", priority=TaskPriority.HIGH)
21async def handle_free_success(checkout_id: uuid.UUID) -> None:
22 async with AsyncSessionMaker() as session:
23 repository = CheckoutRepository.from_session(session)
24 checkout = await repository.get_by_id(
25 checkout_id, options=repository.get_eager_options()
26 )
27 if checkout is None:
28 raise CheckoutDoesNotExist(checkout_id)
29 await checkout_service.handle_success(session, checkout)
32@actor(
33 actor_name="checkout.expire_open_checkouts",
34 cron_trigger=CronTrigger.from_crontab("0,15,30,45 * * * *"),
35 priority=TaskPriority.LOW,
36)
37async def expire_open_checkouts() -> None:
38 async with AsyncSessionMaker() as session:
39 repository = CheckoutRepository.from_session(session)
40 await repository.expire_open_checkouts()