diff --git a/hiboo/cli.py b/hiboo/cli.py index 41153f0b0e740995df60f1de8bba02b7524bf024..e9e70ea69d98a4aa91553de627e56306d0af0833 100644 --- a/hiboo/cli.py +++ b/hiboo/cli.py @@ -1,4 +1,5 @@ from flask import cli +from hiboo import models from hiboo.profile import common import time @@ -21,3 +22,10 @@ def tasks_loop(): while True: common.apply_all_transitions() time.sleep(30) + + +@tasks.command("purge") +def purge(): + # Temporary command to list purgeable accounts before we include + # this in the main task loop + print(models.User.get_unused().all()) diff --git a/hiboo/models.py b/hiboo/models.py index 518dec9222081bd68e22eba6c2ad5713b82bc4dc..b54eef96ad3b972d6a50a9dacd771977eeacc6a4 100644 --- a/hiboo/models.py +++ b/hiboo/models.py @@ -114,6 +114,17 @@ class User(db.Model): profile.status = Profile.ACTIVE return profile + @classmethod + def get_unused(cls, interval=datetime.timedelta(hours=2)): + return (cls.query + .join(cls.profiles.and_(Profile.status != Profile.PURGED), isouter=True) + .filter(Profile.uuid == None) + .filter( + datetime.datetime.now() - interval > + sqlalchemy.sql.func.coalesce(cls.updated_at, cls.created_at) + ) + ) + class Auth(db.Model): """ An authenticator is a method to authenticate a user.