Files
insta/accounts/tasks.py
Beyhan Oğur 2be3a313ad first commit
2026-04-26 22:26:46 +03:00

17 lines
532 B
Python

from celery import shared_task
from django.contrib.auth import get_user_model
from django.utils import timezone
@shared_task(name='accounts.tasks.deactivate_expired_users_task')
def deactivate_expired_users_task():
"""Deactivate active users whose active_until timestamp has passed."""
user_model = get_user_model()
now = timezone.now()
updated = user_model.objects.filter(
is_active=True,
active_until__isnull=False,
active_until__lte=now,
).update(is_active=False)
return updated