# 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)
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)
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):
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,
@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()
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")
# 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