File size: 652 Bytes
9e798a1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import asyncio
from datetime import datetime
from .Model import Subscription
async def deactivate_expired_subscriptions():
while True:
# Find active subscriptions that have expired
expired_subscriptions = await Subscription.filter(
active=True, expiration_time__lt=datetime.now()
)
# Deactivate all expired subscriptions
for subscription in expired_subscriptions:
subscription.active = False
await subscription.save()
# Deactivate the user if he has no plans
# Run this check every hour (or adjust as needed)
await asyncio.sleep(60) # 1 hour
|