Permalink
Browse files

Add url for deleting expired rooms

  • Loading branch information...
1 parent e101126 commit 550c7042420bd2fe351b9cd44fcde3c2d90ba3e6 Esa-Matti Suuronen committed Dec 15, 2011
Showing with 15 additions and 12 deletions.
  1. +7 −5 lib/drawmodel.coffee
  2. +8 −7 whiteboard.coffee
View
@@ -32,14 +32,16 @@ class exports.Drawing extends EventEmitter
, (err, rooms) ->
return cb err if err
- # cb null, rooms
-
- # for r in rooms
- # console.log "in", r.hasExpired(), r.getInactiveTime(), r.inactivityThreshold
-
cb null, rooms.filter (room) ->
room.hasExpired()
+ @deleteExpiredRooms = (cb=->) ->
+ Drawing.findExpiredRooms (err, rooms) ->
+ async.forEachSeries rooms, (r, next) ->
+ console.log "Removing #{ r.toString() }"
+ r.remove next
+ , (err) -> cb err, rooms.length
+
cacheThreshold: 100
View
@@ -17,17 +17,10 @@ urlshortener = require "./lib/urlshortener"
db = require("./db").open()
-setTimeout ->
- Drawing.findExpiredRooms (err, rooms) ->
- for r in rooms
- console.log "got", r.toString()
-, 1000
require("./configure") app, io
-
-
# Simple in-process room manager. This needs work when we have to scale out one
# process
_rooms = {}
@@ -79,6 +72,14 @@ app.post "/", (req, res) ->
res.setHeader "Location", "/" + req.body.roomName
res.send 302
+app.get "/delete", (req, res) ->
+ Drawing.deleteExpiredRooms (err, count) ->
+ if err
+ console.log "Failed to delete", err
+ res.send "Failed to delete", 500
+ else
+ res.send "deleted #{ count }", 200
+
app.get "/bootstrap", (req, res) ->
res.render "bootstrap.jade"

0 comments on commit 550c704

Please sign in to comment.