From e8d7aa7cadcf1449e36bf0a2b94a6b22a5c12f00 Mon Sep 17 00:00:00 2001 From: Andreas Scherbaum Date: Sun, 26 Feb 2012 22:47:17 +0100 Subject: [PATCH] - add periodic maintenance --- docbot.pl | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/docbot.pl b/docbot.pl index 4d41c88..7763353 100755 --- 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 -- 2.39.5