refactor(autorenewal): clean up imports and simplify error handling
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from datetime import datetime, timezone
|
||||
from datetime import UTC, datetime, timedelta
|
||||
|
||||
from sqlalchemy import select, update
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
@@ -10,13 +10,12 @@ class SubscriptionRepository:
|
||||
async def get_subscriptions_for_autorenewal(
|
||||
self, session: AsyncSession, *, days_before_expiry: int = 1
|
||||
) -> list[Subscription]:
|
||||
from datetime import timedelta
|
||||
|
||||
threshold = datetime.now(timezone.utc) + timedelta(days=days_before_expiry)
|
||||
threshold = datetime.now(UTC) + timedelta(days=days_before_expiry)
|
||||
stmt = (
|
||||
select(Subscription)
|
||||
.where(
|
||||
Subscription.autorenew == True,
|
||||
Subscription.autorenew == True, # noqa: E712
|
||||
Subscription.status == SubscriptionStatus.ACTIVE,
|
||||
Subscription.end_date <= threshold,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user