diff --git a/piplmesh/account/tasks.py b/piplmesh/account/tasks.py new file mode 100755 index 00000000..e40dce02 --- /dev/null +++ b/piplmesh/account/tasks.py @@ -0,0 +1,19 @@ +from django.conf import settings +from django.utils import timezone + +from celery import task + +from piplmesh.account import models as account_models +from piplmesh.api import models as api_models + +@task.task +def clean_inactive_lazy_users(): + users_with_content = [] + for post in api_models.Post.objects: + users_with_content.append(post.author) + for comment in post.comments: + users_with_content.append(comment.author) + users_with_content = list(set(users_with_content)) + for user in account_models.User.objects: + if not user.is_authenticated() and (timezone.now() - user.connection_last_unsubscribe).days >= settings.LAZY_USER_EXPIRATION and user not in users_with_content: + user.delete() \ No newline at end of file diff --git a/piplmesh/settings.py b/piplmesh/settings.py index 911de9c9..0db24520 100644 --- a/piplmesh/settings.py +++ b/piplmesh/settings.py @@ -217,6 +217,9 @@ ), } +CHECK_ONLINE_USERS_INTERVAL = 10 # seconds +CLEAN_INACTIVE_USERS_INTERVAL = 1 # days +LAZY_USER_EXPIRATION = 30 # days CHECK_ONLINE_USERS_INTERVAL = 10 # seconds CHECK_FOR_NEW_HOROSCOPE = 6 # am every day @@ -241,6 +244,11 @@ 'schedule': crontab(hour=CHECK_FOR_NEW_HOROSCOPE), 'args': (), }, + 'clean_inactive_lazy_users': { + 'task': 'piplmesh.account.tasks.clean_inactive_lazy_users', + 'schedule': datetime.timedelta(days=CLEAN_INACTIVE_USERS_INTERVAL), + 'args': (), + }, } # A sample logging configuration. The only tangible logging