hotspot / App /Subscriptions /BackgroundTask.py
Mbonea's picture
testing deployment
9e798a1
raw
history blame
652 Bytes
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