17 lines
532 B
Python
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
|