- add periodic maintenance
authorAndreas Scherbaum <[email protected]>
Sun, 26 Feb 2012 21:47:17 +0000 (22:47 +0100)
committerAndreas Scherbaum <[email protected]>
Sun, 26 Feb 2012 21:47:17 +0000 (22:47 +0100)
docbot.pl

index 4d41c88c08163af7da1b31b74d665e2a445b273f..7763353df5f263ce1f9796168b87d70000a45ab4 100755 (executable)
--- a/docbot.pl
+++ b/docbot.pl
@@ -231,6 +231,29 @@ POE::Session->create(
 );
 
 
+# this POE session will start maintenance operations
+# ticked every 5 minutes
+POE::Session->create(
+    inline_states => {
+        _start => sub {
+            # start the next tick
+            $_[HEAP]->{next_alarm_time} = int(time()) + 60 * 5;
+            $_[KERNEL]->alarm(tick => $_[HEAP]->{next_alarm_time});
+        },
+
+        # a tick every 5 minutes
+        tick => sub {
+            # make sure the next tick is initialized
+            $_[HEAP]->{next_alarm_time} = $_[HEAP]->{next_alarm_time} + 60 * 5;
+            $_[KERNEL]->alarm(tick => $_[HEAP]->{next_alarm_time});
+
+            # call the real maintenance function
+            maintenance();
+        },
+    },
+);
+
+
 
 
 
@@ -742,7 +765,7 @@ sub find_irc_session {
 
 # watchdog()
 #
-# verify connections
+# verify network connections
 #
 # parameter:
 #  none
@@ -790,6 +813,23 @@ BEGIN {
 }
 
 
+# maintenance()
+#
+# verify database connection, do some maintenance
+#
+# parameter:
+#  none
+# return:
+#  none
+sub maintenance {
+    if (!test_database()) {
+        print_msg("Database not connected!", ERROR);
+    }
+
+    # FIXME: update website cache
+}
+
+
 # send_to_commandchannel()
 #
 # send a message to the command channel