From bc371f1ef39f3d93fb31c66f0a3e0b44fc8c20cc Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Wed, 24 Nov 2021 17:58:03 +0000 Subject: [PATCH] Delete inactive user accounts after 12 hours --- .dockerignore | 1 + app/tasks/__init__.py | 17 +++++++++++------ app/tasks/usertasks.py | 26 ++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 app/tasks/usertasks.py diff --git a/.dockerignore b/.dockerignore index 0481319..a877f0f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,3 +3,4 @@ data* uploads *.pyc __pycache__ +env diff --git a/app/tasks/__init__.py b/app/tasks/__init__.py index 5b97a8a..0e154ed 100644 --- a/app/tasks/__init__.py +++ b/app/tasks/__init__.py @@ -13,6 +13,7 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . + from logging import Filter import flask @@ -67,24 +68,28 @@ celery = make_celery(app) CELERYBEAT_SCHEDULE = { 'topic_list_import': { 'task': 'app.tasks.forumtasks.importTopicList', - 'schedule': crontab(minute=1, hour=1), + 'schedule': crontab(minute=1, hour=1), # 0101 }, 'package_score_update': { 'task': 'app.tasks.pkgtasks.updatePackageScores', - 'schedule': crontab(minute=10, hour=1), + 'schedule': crontab(minute=10, hour=1), # 0110 }, 'check_for_updates': { 'task': 'app.tasks.importtasks.check_for_updates', - 'schedule': crontab(minute=10, hour=1), + 'schedule': crontab(minute=10, hour=1), # 0110 }, 'send_pending_notifications': { 'task': 'app.tasks.emails.send_pending_notifications', - 'schedule': crontab(minute='*/5'), + 'schedule': crontab(minute='*/5'), # every 5 minutes }, 'send_notification_digests': { 'task': 'app.tasks.emails.send_pending_digests', - 'schedule': crontab(minute=0, hour=14), - } + 'schedule': crontab(minute=0, hour=14), # 1400 + }, + 'delete_inactive_users': { + 'task': 'app.tasks.users.delete_inactive_users', + 'schedule': crontab(minute=15), # every hour at quarter past + }, } celery.conf.beat_schedule = CELERYBEAT_SCHEDULE diff --git a/app/tasks/usertasks.py b/app/tasks/usertasks.py new file mode 100644 index 0000000..7fb7594 --- /dev/null +++ b/app/tasks/usertasks.py @@ -0,0 +1,26 @@ +# ContentDB +# Copyright (C) 2021 rubenwardy +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + + +import datetime +from app.models import User +from app.tasks import celery + + +@celery.task() +def delete_inactive_users(): + threshold = datetime.datetime.now() - datetime.timedelta(hours=12) + User.query.filter(User.is_active==False, User.packages==None, User.created_at<=threshold).delete()