summaryrefslogtreecommitdiff
path: root/lib/Multi
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Multi')
-rw-r--r--lib/Multi/Anime.pm11
-rw-r--r--lib/Multi/Core.pm14
2 files changed, 14 insertions, 11 deletions
diff --git a/lib/Multi/Anime.pm b/lib/Multi/Anime.pm
index 17b9a3b0..a17eead6 100644
--- a/lib/Multi/Anime.pm
+++ b/lib/Multi/Anime.pm
@@ -10,6 +10,7 @@ use warnings;
use Multi::Core;
use AnyEvent::Socket;
use AnyEvent::Util;
+use Encode 'decode_utf8', 'encode_utf8';
sub LOGIN_ACCEPTED () { 200 }
@@ -37,7 +38,7 @@ my %O = (
client => 'multi',
clientver => 1,
# Misc settings
- msgdelay => 10,
+ msgdelay => 30,
timeout => 30,
timeoutdelay => 0.4, # $delay = $msgdelay ** (1 + $tm*$timeoutdelay)
maxtimeoutdelay => 2*3600,
@@ -98,7 +99,7 @@ sub unload {
sub check_anime {
return if $C{aid};
- pg_cmd 'SELECT id FROM anime WHERE lastfetch IS NULL OR lastfetch < NOW() - $1::interval LIMIT 1', [ $O{cachetime} ], sub {
+ pg_cmd 'SELECT id FROM anime WHERE lastfetch IS NULL OR lastfetch < NOW() - $1::interval ORDER BY lastfetch DESC NULLS FIRST LIMIT 1', [ $O{cachetime} ], sub {
my $res = shift;
return if pg_expect $res, 1 or $C{aid} or !$res->rows;
$C{aid} = $res->value(0,0);
@@ -132,7 +133,8 @@ sub nextcmd {
# anyway.
my $cmd = fmtcmd(%cmd);
AE::log debug => "Sending command: $cmd";
- my $n = syswrite $C{sock}, fmtcmd(%cmd);
+ $cmd = encode_utf8 $cmd;
+ my $n = syswrite $C{sock}, $cmd;
AE::log warn => sprintf "Didn't write command: only sent %d of %d bytes: %s", $n, length($cmd), $! if $n != length($cmd);
$C{tw} = AE::timer $O{timeout}, 0, \&handletimeout;
@@ -158,6 +160,7 @@ sub receivemsg {
my $n = sysread $C{sock}, $buf, 4096;
return AE::log warn => "sysread() failed: $!" if $n < 0;
+ $buf = decode_utf8 $buf;
my $time = AE::now-$C{lm};
AE::log debug => sprintf "Received message in %.2fs: %s", $time, $buf;
@@ -205,7 +208,7 @@ sub handlemsg {
# we now know something about the anime we requested, update DB
elsif($code == NO_SUCH_ANIME) {
AE::log info => "No anime found with id = $C{aid}";
- pg_cmd 'UPDATE anime SET lastfetch = NOW() WHERE id = ?', [ $C{aid} ];
+ pg_cmd 'UPDATE anime SET lastfetch = NOW() WHERE id = $1', [ $C{aid} ];
$f = \&check_anime;
$C{aid} = 0;
diff --git a/lib/Multi/Core.pm b/lib/Multi/Core.pm
index 7bffef52..82b3a9c6 100644
--- a/lib/Multi/Core.pm
+++ b/lib/Multi/Core.pm
@@ -122,13 +122,13 @@ sub run {
die "PID file already exists\n" if -e $pidfile;
$stopcv = AE::cv;
- AnyEvent::Log::ctx('Multi')->attach(AnyEvent::Log::Ctx->new(level => $VNDB::M{log_level}, log_to_file => $VNDB::M{log_dir}.'/multi.log'));
- #log_cb => sub {
- # open(my $F, '>>:utf8', $VNDB::M{log_dir}.'/multi.log');
- # print $F $_[0];
- # close $F;
- # }
- #));
+ AnyEvent::Log::ctx('Multi')->attach(AnyEvent::Log::Ctx->new(level => $VNDB::M{log_level}, # log_to_file => $VNDB::M{log_dir}.'/multi.log'));
+ # Don't use log_to_file, it doesn't accept perl's unicode strings (and, in fact, crashes on them without logging anything).
+ log_cb => sub {
+ open(my $F, '>>:utf8', $VNDB::M{log_dir}.'/multi.log');
+ print $F $_[0];
+ }
+ ));
$AnyEvent::Log::FILTER->level('fatal');
daemon_init;