]> git.ipfire.org Git - ipfire.org.git/commitdiff
Cleanup sessions, accounts and the message queue once an hour
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 7 May 2019 16:44:37 +0000 (17:44 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 7 May 2019 16:44:37 +0000 (17:44 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/backend/accounts.py
src/backend/base.py
src/backend/messages.py
src/crontab/ipfire.org

index f6b7dc6c66c90761accac3783f18211f559e4826..74b5ff00ec2da74f88540d9f9879ff6472d168bc 100644 (file)
@@ -212,12 +212,7 @@ class Accounts(Object):
 
        # Session stuff
 
-       def _cleanup_expired_sessions(self):
-               self.db.execute("DELETE FROM sessions WHERE time_expires <= NOW()")
-
        def create_session(self, account, host):
-               self._cleanup_expired_sessions()
-
                res = self.db.get("INSERT INTO sessions(host, uid) VALUES(%s, %s) \
                        RETURNING session_id, time_expires", host, account.uid)
 
@@ -234,7 +229,6 @@ class Accounts(Object):
 
                self.db.execute("DELETE FROM sessions \
                        WHERE session_id = %s AND host = %s", session_id, host)
-               self._cleanup_expired_sessions()
 
        def get_by_session(self, session_id, host):
                logging.debug("Looking up session %s" % session_id)
@@ -253,6 +247,13 @@ class Accounts(Object):
 
                return self.get_by_uid(res.uid)
 
+       def cleanup(self):
+               # Cleanup expired sessions
+               self.db.execute("DELETE FROM sessions WHERE time_expires <= NOW()")
+
+               # Cleanup expired account activations
+               self.db.execute("DELETE FROM account_activations WHERE expires_at <= NOW()")
+
 
 class Account(Object):
        def __init__(self, backend, dn, attrs=None):
index 6c79d8bf44406e4de7d85241b107a6ebabe1ef42..f11b5ad5f3350dbfc7f9dfd16069b0e380973699 100644 (file)
@@ -90,7 +90,7 @@ class Backend(object):
        def run_task(self, task, *args, **kwargs):
                tasks = {
                        "check-mirrors"     : self.mirrors.check_all,
-                       "cleanup-messages"  : self.messages.queue.cleanup,
+                       "cleanup"           : self.cleanup,
                        "scan-files"        : self.releases.scan_files,
                        "send-all-messages" : self.messages.queue.send_all,
                        "tweet"             : self.tweets.tweet,
@@ -117,3 +117,13 @@ class Backend(object):
        @lazy_property
        def tweets(self):
                return tweets.Tweets(self)
+
+       @tornado.gen.coroutine
+       def cleanup(self):
+               # Cleanup message queue
+               with self.db.transaction():
+                       self.messages.queue.cleanup()
+
+               # Cleanup in accounts
+               with self.db.transaction():
+                       self.accounts.cleanup()
index 1cf906900c0be36dc6fe5dbef9e9658591f64339..59942c5a931e832ffafe7c1b756aa007fbcee971 100644 (file)
@@ -219,7 +219,6 @@ class Queue(misc.Object):
                        self.db.execute("UPDATE messages SET time_sent = NOW() \
                                WHERE id = %s", message.id)
 
-       @tornado.gen.coroutine
        def cleanup(self):
                logging.debug("Cleaning up message queue")
 
index b5b7459863b84b51e6007bac0050acb32bbef28b..5c02a6e455b4b090bf61091f9fd15ae9b2135b1a 100644 (file)
@@ -7,8 +7,8 @@
 # Send messages
 * * * * *      nobody  ipfire.org send-all-messages
 
-# Cleanup once a an hour
-30 * * * *     nobody  ipfire.org cleanup-messages
+# Cleanup once an hour
+30 * * * *     nobody  ipfire.org cleanup
 
 # Check mirrors once every 30 min
 */30 * * * *   nobody  ipfire.org check-mirrors