Delete inactive user accounts after 12 hours

This commit is contained in:
rubenwardy 2021-11-24 17:58:03 +00:00
parent 0486eb76c0
commit bc371f1ef3
3 changed files with 38 additions and 6 deletions

@ -3,3 +3,4 @@ data*
uploads uploads
*.pyc *.pyc
__pycache__ __pycache__
env

@ -13,6 +13,7 @@
# #
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
from logging import Filter from logging import Filter
import flask import flask
@ -67,24 +68,28 @@ celery = make_celery(app)
CELERYBEAT_SCHEDULE = { CELERYBEAT_SCHEDULE = {
'topic_list_import': { 'topic_list_import': {
'task': 'app.tasks.forumtasks.importTopicList', 'task': 'app.tasks.forumtasks.importTopicList',
'schedule': crontab(minute=1, hour=1), 'schedule': crontab(minute=1, hour=1), # 0101
}, },
'package_score_update': { 'package_score_update': {
'task': 'app.tasks.pkgtasks.updatePackageScores', 'task': 'app.tasks.pkgtasks.updatePackageScores',
'schedule': crontab(minute=10, hour=1), 'schedule': crontab(minute=10, hour=1), # 0110
}, },
'check_for_updates': { 'check_for_updates': {
'task': 'app.tasks.importtasks.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': { 'send_pending_notifications': {
'task': 'app.tasks.emails.send_pending_notifications', 'task': 'app.tasks.emails.send_pending_notifications',
'schedule': crontab(minute='*/5'), 'schedule': crontab(minute='*/5'), # every 5 minutes
}, },
'send_notification_digests': { 'send_notification_digests': {
'task': 'app.tasks.emails.send_pending_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 celery.conf.beat_schedule = CELERYBEAT_SCHEDULE

26
app/tasks/usertasks.py Normal file

@ -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 <https://www.gnu.org/licenses/>.
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()