]> git.donarmstrong.com Git - infobot.git/blobdiff - src/IRC/Schedulers.pl
- I broke maths when I tried to fix "999!" - fixed :-)
[infobot.git] / src / IRC / Schedulers.pl
index 4566df6872f2047dba1554a33480900108d3858f..403e3185f051f8ea2b73bc4c58170d886c836057 100644 (file)
@@ -37,7 +37,7 @@ sub setupSchedulers {
     &freshmeatLoop(2);
     &kernelLoop(2);
     &wingateWriteFile(2);
-    &factoidCheck(2);
+    &factoidCheck(1);
     &newsFlush(1);
 
 #    my $count = map { exists $sched{$_}{TIME} } keys %sched;
@@ -294,7 +294,7 @@ sub newsFlush {
        my $i           = 0;
        my $total       = scalar(keys %{ $::news{$chan} });
 
-       &DEBUG("newsFlush: chan => $chan");
+       &DEBUG("newsFlush: chan => $chan (total => $total)");
 
        foreach $item (keys %{ $::news{$chan} }) {
            my $t = $::news{$chan}{$item}{Expire};
@@ -341,12 +341,14 @@ sub newsFlush {
            delete $::newsuser{$chan}{$_};
            $duser++;
        }
+
+       my $i = scalar(keys %{ $::newsuser{$chan} });
+       delete $::newsuser{$chan} unless ($i);
     }
 
     if ($delete or $duser) {
-       &DEBUG("newsF: Writing news.");
        &News::writeNews();
-       &status("NEWS (newsflush) deleted: $delete news entries; $duser user cache.");
+       &status("NewsFlush: deleted: $delete news entries; $duser user cache.");
     }
 }
 
@@ -358,6 +360,9 @@ sub chanlimitCheck {
        return if ($_[0] eq "2");
     }
 
+    $cache{chanlimitCheck}++;
+    &DEBUG("clC: chanlimitCheck => $cache{chanlimitCheck}");
+
     foreach $chan ( &ChanConfList("chanlimitcheck") ) {
        next unless (&validChan($chan));
 
@@ -419,39 +424,55 @@ sub netsplitCheck {
        return if ($_[0] eq "2");
     }
 
-    &DEBUG("running netsplitCheck...");
+    $cache{'netsplitCache'}++;
+    &DEBUG("running netsplitCheck... $cache{netsplitCache}");
+
+    if (!scalar %netsplit and scalar %netsplitservers) {
+       &DEBUG("nsc: FIRST!!! ok hash netsplit is NULL; purging hash netsplitservers");
+       undef %netsplitservers;
+    }
 
     foreach $s1 (keys %netsplitservers) {
-       &DEBUG("nsC: s1 => $s1");
 
        foreach $s2 (keys %{ $netsplitservers{$s1} }) {
            my $delta = time() - $netsplitservers{$s1}{$s2};
-           &DEBUG("nss{$s1}{$s2} = $delta");
 
-           if (time() - $netsplitservers{$s1}{$s2} > 3600) {
+           if ($delta > 3600) {
                &status("netsplit between $s1 and $s2 appears to be stale.");
                delete $netsplitservers{$s1}{$s2};
+               &chanlimitCheck();
            }
        }
+
+       my $i = scalar(keys %{ $netsplitservers{$s1} });
+       delete $netsplitservers{$s1} unless ($i);
     }
 
     # %netsplit hash checker.
     my $count  = scalar keys %netsplit;
+    my(@delete);
     foreach (keys %netsplit) {
        if (&IsNickInAnyChan($_)) {
            &DEBUG("netsplitC: $_ is in some chan; removing from netsplit list.");
            delete $netsplit{$_};
            next;
        }
-       next unless (time() - $netsplit{$_} > 60*10);
+       # todo: change time value?
+       next unless (time() - $netsplit{$_} > 60*30);
 
-       &DEBUG("netsplitC: $_ didn't come back from netsplit; removing from netsplit list.");
+       push(@delete, $_);
        delete $netsplit{$_};
     }
 
+    &DEBUG("removed from netsplit list (".scalar(@delete)."): @delete") if (@delete);
     &DEBUG("nsC: netsplitservers: ".scalar(keys %netsplitservers) );
     &DEBUG("nsC: netsplit: ".scalar(keys %netsplit) );
 
+    if (!scalar %netsplit and scalar %netsplitservers) {
+       &DEBUG("nsc: ok hash netsplit is NULL; purging hash netsplitservers");
+       undef %netsplitservers;
+    }
+
     if ($count and !scalar keys %netsplit) {
        &DEBUG("nsC: netsplit is hopefully gone. reinstating chanlimit check.");
        &chanlimitCheck();
@@ -567,7 +588,7 @@ sub seenFlush {
        &DEBUG("seenFlush: NO VALID FACTOID SUPPORT?");
     }
 
-    &status("Flushed $flushed seen entries.")          if ($flushed);
+    &status("Seen: Flushed $flushed entries.") if ($flushed);
     &VERB(sprintf("  new seen: %03.01f%% (%d/%d)",
        $stats{'new'}*100/($stats{'count_old'} || 1),
        $stats{'new'}, ( $stats{'count_old'} || 1) ), 2) if ($stats{'new'});
@@ -1025,7 +1046,7 @@ sub wingateWriteFile {
 
 sub factoidCheck {
     if (@_) {
-       &ScheduleThis(1440, "factoidCheck");
+       &ScheduleThis(720, "factoidCheck");
        return if ($_[0] eq "2");       # defer.
     }
 
@@ -1035,6 +1056,7 @@ sub factoidCheck {
 
     foreach (@list) {
        my $age = &getFactInfo($_, "modified_time");    
+       &DEBUG("fC: _ => '$_'; age => $age");
 
        if (!defined $age or $age !~ /^\d+$/) {
            if (scalar @list > 50) {
@@ -1045,16 +1067,19 @@ sub factoidCheck {
                }
            }
 
-           &WARN("old cruft (no time): $_");
+           &WARN("del factoid: old cruft (no time): $_");
            &delFactoid($_);
            next;
        }
 
+       &DEBUG("del factoid: delta => ".($time - $age) );
+       &DEBUG("del factoid:    stale => $stale");
        next unless ($time - $age > $stale);
 
        my $fix = $_;
        $fix =~ s/ #DEL#$//g;
-       &DEBUG("safedel: Removing $fix ($_) for good.");
+       my $agestr = &Time2String($time - $age);
+       &DEBUG("safedel: Removing '$_' for good. [$agestr old]");
 
        &delFactoid($_);
     }