From d07254653db162243435bf18cd9e86b2b76898bf Mon Sep 17 00:00:00 2001 From: Jure Bajt Date: Sat, 9 Jun 2012 12:42:47 +0200 Subject: [PATCH 1/3] Added celery taks to remove inactive lazy users. --- piplmesh/account/tasks.py | 21 +++++++++++++++++++++ piplmesh/settings.py | 8 ++++++++ 2 files changed, 29 insertions(+) create mode 100755 piplmesh/account/tasks.py diff --git a/piplmesh/account/tasks.py b/piplmesh/account/tasks.py new file mode 100755 index 00000000..85605cd0 --- /dev/null +++ b/piplmesh/account/tasks.py @@ -0,0 +1,21 @@ +import datetime + +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 base, 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.DELETE_LAZY_USER_AFTER_DAYS 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 a9f2d04d..bec20191 100644 --- a/piplmesh/settings.py +++ b/piplmesh/settings.py @@ -204,6 +204,8 @@ } CHECK_ONLINE_USERS_INTERVAL = 10 +CLEAN_INACTIVE_USERS_INTERVAL = 1 +DELETE_LAZY_USER_AFTER_DAYS = 30 CELERY_RESULT_BACKEND = 'mongodb' CELERY_MONGODB_BACKEND_SETTINGS = { @@ -222,6 +224,7 @@ CELERY_IMPORTS = ( 'piplmesh.frontend.tasks', + 'piplmesh.account.tasks', ) CELERYBEAT_SCHEDULE = { @@ -230,6 +233,11 @@ 'schedule': datetime.timedelta(seconds=CHECK_ONLINE_USERS_INTERVAL), '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 From d2e45d888acae91fa221591fea1706f8b1538f23 Mon Sep 17 00:00:00 2001 From: Jure Bajt Date: Sat, 9 Jun 2012 12:46:54 +0200 Subject: [PATCH 2/3] Removed unneeded import. --- piplmesh/account/tasks.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/piplmesh/account/tasks.py b/piplmesh/account/tasks.py index 85605cd0..5f40a194 100755 --- a/piplmesh/account/tasks.py +++ b/piplmesh/account/tasks.py @@ -1,5 +1,3 @@ -import datetime - from django.conf import settings from django.utils import timezone From 13c26ed01319c63c5091737f111829e9b51c4e35 Mon Sep 17 00:00:00 2001 From: Jure Bajt Date: Sat, 9 Jun 2012 15:22:52 +0200 Subject: [PATCH 3/3] Aesthetic fixes. --- piplmesh/account/tasks.py | 4 ++-- piplmesh/settings.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/piplmesh/account/tasks.py b/piplmesh/account/tasks.py index 5f40a194..e40dce02 100755 --- a/piplmesh/account/tasks.py +++ b/piplmesh/account/tasks.py @@ -4,7 +4,7 @@ from celery import task from piplmesh.account import models as account_models -from piplmesh.api import base, models as api_models +from piplmesh.api import models as api_models @task.task def clean_inactive_lazy_users(): @@ -15,5 +15,5 @@ def clean_inactive_lazy_users(): 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.DELETE_LAZY_USER_AFTER_DAYS and user not in users_with_content: + 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 bec20191..64ff2363 100644 --- a/piplmesh/settings.py +++ b/piplmesh/settings.py @@ -203,9 +203,9 @@ ), } -CHECK_ONLINE_USERS_INTERVAL = 10 -CLEAN_INACTIVE_USERS_INTERVAL = 1 -DELETE_LAZY_USER_AFTER_DAYS = 30 +CHECK_ONLINE_USERS_INTERVAL = 10 # seconds +CLEAN_INACTIVE_USERS_INTERVAL = 1 # days +LAZY_USER_EXPIRATION = 30 # days CELERY_RESULT_BACKEND = 'mongodb' CELERY_MONGODB_BACKEND_SETTINGS = { @@ -223,8 +223,8 @@ BROKER_VHOST = 'celery' CELERY_IMPORTS = ( - 'piplmesh.frontend.tasks', 'piplmesh.account.tasks', + 'piplmesh.frontend.tasks', ) CELERYBEAT_SCHEDULE = {