summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Moore <neil@s-z.org>2013-05-30 10:27:06 -0500
committerNeil Moore <neil@s-z.org>2013-05-30 10:27:06 -0500
commitfb0bc5c88807f5f03a18b876033951429038dbbb (patch)
tree4249ae0682b410b6ed50787a03dd5eefd3d55964
parent44ee0cfb9b1d9cc5454e72d8de811bae76123a16 (diff)
downloadcrawlbot-fb0bc5c88807f5f03a18b876033951429038dbbb.tar.gz
crawlbot-fb0bc5c88807f5f03a18b876033951429038dbbb.zip
Tick more frequently, but don't do stuff on every tick.
Tick every five seconds. When we get a tick we check for the existence of a "poke" file that tells us to update. If that exists, or the number of unhandled ticks is greater than 60, then run the plugins.
-rw-r--r--lib/Crawl/Bot.pm18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/Crawl/Bot.pm b/lib/Crawl/Bot.pm
index 21b6a33..135bef7 100644
--- a/lib/Crawl/Bot.pm
+++ b/lib/Crawl/Bot.pm
@@ -29,7 +29,13 @@ has data_dir => (
has update_time => (
is => 'ro',
isa => 'Int',
- default => 300,
+ default => 5,
+);
+
+has force_update_frequency => (
+ is => 'ro',
+ isa => 'Int',
+ default => 60, # Measured in ticks
);
has plugins => (
@@ -58,8 +64,18 @@ before say => sub {
$_->sent({%params, who => $self->nick}) for @{ $self->plugins };
};
+my $tickcount = 0;
sub tick {
my $self = shift;
+ my $pokefile = File::Spec->catfile($self->data_dir, "poke");
+
+ if (++$tickcount < $self->force_update_frequency and ! -f $pokefile) {
+ return $self->update_time;
+ } else {
+ $tickcount = 0;
+ -f $pokefile and unlink $pokefile;
+ }
+
print STDERR "Checking for updates at " . localtime() . ":\n";
for (@{ $self->plugins }) {
print STDERR " --- " . ref($_);