LOC-6 Switch to shorter values and insert print for testing
LOC-6 Switch to shorter values and insert print for testing

Configures to run the scheduler every minute and expire messages after a minute.

Created a room, joined it, posted some messages and then left.

Scheduler dumped the following to stdout

1526729206.144380 Request start
{u'action': u'schedulerTrigger', u'pass': u'GRu5yYY8ngPGtBfbl6wYTdVA7R5CtYPuTjkG4Xh2SfcClhdEaMQmx9JCWhqQDCtg'}
Tidying
Start 8 messages
End 8 messages
127.0.0.1 - - [19/May/2018 12:26:46] "POST / HTTP/1.1" 200 -
1526729266.210174 Request start
{u'action': u'schedulerTrigger', u'pass': u'GRu5yYY8ngPGtBfbl6wYTdVA7R5CtYPuTjkG4Xh2SfcClhdEaMQmx9JCWhqQDCtg'}
Tidying
Start 8 messages
End 0 messages
127.0.0.1 - - [19/May/2018 12:27:46] "POST / HTTP/1.1" 200 -
1526729326.238788 Request start
{u'action': u'schedulerTrigger', u'pass': u'GRu5yYY8ngPGtBfbl6wYTdVA7R5CtYPuTjkG4Xh2SfcClhdEaMQmx9JCWhqQDCtg'}
Tidying
Start 0 messages
End 0 messages

As the auto-purge is an important function, should probably make the period configurable so that we can write automated tests to verify the behaviour.

--- a/server/LocalChat.py
+++ b/server/LocalChat.py
@@ -656,7 +656,7 @@
             return 403
         
         # Tidy messages older than 10 minutes
-        self.tidyMsgs(time.time() - 600);
+        self.tidyMsgs(time.time() - 60); # TODO - change this back to 600 once testing complete
         
         
         return {'status':'ok'}
@@ -668,6 +668,11 @@
         '''
         
         print "Tidying"
+        
+        self.cursor.execute("SELECT COUNT(*) from messages")
+        r = self.cursor.fetchone()
+        print "Start %s messages" % (r[0],)
+        
         if room:
             # Tidy from a specific room
             self.cursor.execute("DELETE FROM messages where ts < ? and room = ?",(thresholdtime,room))
@@ -676,6 +681,11 @@
         else:
             self.cursor.execute("DELETE FROM messages where ts < ?",(thresholdtime,))
             self.conn.commit()
+
+
+        self.cursor.execute("SELECT COUNT(*) from messages")
+        r = self.cursor.fetchone()
+        print "End %s messages" % (r[0],)
 
 
         # Tidy away any failure messages