Permalink
Browse files

add maintenance url to clean old sessions, call with a cron job

  • Loading branch information...
feross committed Aug 31, 2012
1 parent a6e7bad commit 024bebb73be3f1aed5f3ac60f828142eb613eac3
Showing with 14 additions and 2 deletions.
  1. +10 −0 server/handlers.py
  2. +3 −2 server/server.py
  3. +1 −0 server/templates/maintenance.html
View
@@ -60,6 +60,10 @@ def get_current_session(self):
return self._current_session
+ def clear_old_sessions(self):
+ self.db_session.execute("DELETE FROM sessions WHERE `create_date` < CURDATE() - 30")
+ self.db_session.flush()
+
def get_profile_url(self):
user = self.get_current_user()
return '/user/' + user.profile if user is not None else ''
@@ -246,6 +250,11 @@ class TermsHandler(HandlerBase):
def get(self):
self.render("terms.html")
+class MaintenanceHandler(HandlerBase):
+ def get(self):
+ self.clear_old_sessions()
+ self.render("maintenance.html")
+
class PlaylistHandler(PlaylistHandlerBase):
"""Landing page for a playlist"""
def get(self, playlist_alpha_id):
@@ -500,3 +509,4 @@ def on_response(self, response):
class ErrorHandler(HandlerBase):
def prepare(self):
self.send_error(404)
+
View
@@ -23,6 +23,7 @@ def __init__(self):
(r"/p/([a-zA-Z0-9]+)/?$", handlers.PlaylistHandler),
(r"/terms/?$", handlers.TermsHandler),
(r"/search/?$", handlers.SearchHandler),
+ (r"/maintenance/?", handlers.MaintenanceHandler),
(r"/tts/[0-9a-f]+.mp3$", handlers.TTSHandler),
(r"/([^/]+)/album/([^/]+)/?", handlers.AlbumHandler),
(r"/([^/]+)/([^/]+)/?", handlers.SongHandler),
@@ -34,8 +35,8 @@ def __init__(self):
def main():
- # Code to daemonize tornado.
- # Not used in production since supervisord requires non-daemonized processes.
+ # Code to daemonize tornado.
+ # Not used in production since supervisord requires non-daemonized processes.
if options.cli_args.daemonize:
try:
import daemon
@@ -0,0 +1 @@
+done!

1 comment on commit 024bebb

@feross

This comment has been minimized.

Show comment Hide comment
@feross

feross Aug 31, 2012

Owner

@JakeBecker Just doing more server admin stuff and I noticed that our sessions table had almost 300,000 rows! We were never deleting old sessions. So, I just added a URL /maintenance that deletes all sessions older than 30 days when you visit it. I'll make a cron job that hits that url every so often.

:)

Owner

feross commented on 024bebb Aug 31, 2012

@JakeBecker Just doing more server admin stuff and I noticed that our sessions table had almost 300,000 rows! We were never deleting old sessions. So, I just added a URL /maintenance that deletes all sessions older than 30 days when you visit it. I'll make a cron job that hits that url every so often.

:)

Please sign in to comment.