From fb0bc5c88807f5f03a18b876033951429038dbbb Mon Sep 17 00:00:00 2001 From: Neil Moore Date: Thu, 30 May 2013 10:27:06 -0500 Subject: 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. --- lib/Crawl/Bot.pm | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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($_); -- cgit v1.2.3-54-g00ecf