Coverage for polar/customer_meter/tasks.py: 46%
22 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.customer.repository import CustomerRepository
4from polar.exceptions import PolarTaskError
5from polar.locker import Locker
6from polar.worker import AsyncSessionMaker, RedisMiddleware, TaskPriority, actor
8from .service import customer_meter as customer_meter_service
11class CustomerMeterTaskError(PolarTaskError): ... 11 ↛ 14line 11 didn't jump to line 14 because
14class CustomerDoesNotExist(CustomerMeterTaskError):
15 def __init__(self, customer_id: uuid.UUID) -> None:
16 self.customer_id = customer_id
17 message = f"The customer with id {customer_id} does not exist."
18 super().__init__(message)
21@actor(
22 actor_name="customer_meter.update_customer",
23 priority=TaskPriority.LOW,
24 max_retries=1,
25 min_backoff=30_000,
26)
27async def update_customer(customer_id: uuid.UUID) -> None:
28 async with AsyncSessionMaker() as session:
29 repository = CustomerRepository.from_session(session)
30 customer = await repository.get_by_id(customer_id)
31 if customer is None:
32 raise CustomerDoesNotExist(customer_id)
34 redis = RedisMiddleware.get()
35 locker = Locker(redis)
37 await customer_meter_service.update_customer(session, locker, customer)