summaryrefslogtreecommitdiff
path: root/lib/Multi
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2009-07-18 15:48:32 +0200
committerYorhel <git@yorhel.nl>2009-07-18 15:48:32 +0200
commit5cbaaa3616a002a708af785bfa7e0774d50e0751 (patch)
treef82f4f03b439807b135cce2884e4e95ee71c8722 /lib/Multi
parent0a3ebf61cb7ea608f440029c2f138d97fb5a102a (diff)
Use PostgreSQL's LISTEN/NOTIFY to notify Multi::Anime for new anime
The notify is called from a trigger function, which is called on any UPDATE or INSERT INTO query of which the lastfetch column is NULL. This guarantees that anime info in the DB will always be updated, no matter how its inserted.
Diffstat (limited to 'lib/Multi')
-rw-r--r--lib/Multi/Anime.pm6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/Multi/Anime.pm b/lib/Multi/Anime.pm
index b1d5ed3e..bc01d26e 100644
--- a/lib/Multi/Anime.pm
+++ b/lib/Multi/Anime.pm
@@ -79,6 +79,9 @@ sub _start {
$_[KERNEL]->alias_set('anime');
$_[KERNEL]->sig(shutdown => 'shutdown');
+ # listen for 'anime' notifies
+ $_[KERNEL]->post(pg => listen => anime => 'check_anime');
+
# init the UDP 'connection'
$_[HEAP]{w} = POE::Wheel::UDP->new(
(map { $_ => $_[HEAP]{$_} } qw| LocalAddr LocalPort PeerAddr PeerPort |),
@@ -93,6 +96,7 @@ sub _start {
sub shutdown {
undef $_[HEAP]{w};
+ $_[KERNEL]->post(pg => unlisten => 'anime');
$_[KERNEL]->delay('check_anime');
$_[KERNEL]->delay('nextcmd');
$_[KERNEL]->delay('receivepacket');
@@ -109,7 +113,7 @@ sub check_anime {
sub fetch_anime { # num, res
# nothing to do, check again later
- return $_[KERNEL]->delay('check_anime', $_[HEAP]{check_delay}) if !$_[ARG0] == 0;
+ return $_[KERNEL]->delay('check_anime', $_[HEAP]{check_delay}) if $_[ARG0] == 0;
# otherwise, fetch info (if we aren't doing so already)
return if $_[HEAP]{aid};