{
$Koha::Contrib::Tamil::IndexerDaemon::VERSION
=
'0.013'
;
}
use
5.010;
has
name
=> (
is
=>
'rw'
,
isa
=>
'Str'
);
has
conf
=> (
is
=>
'rw'
,
isa
=>
'Str'
);
has
directory
=> (
is
=>
'rw'
,
isa
=>
'Str'
);
has
timeout
=> (
is
=>
'rw'
,
isa
=>
'Int'
,
default
=> 60,
);
has
verbose
=> (
is
=>
'rw'
,
isa
=>
'Bool'
,
default
=> 0 );
has
koha
=> (
is
=>
'rw'
,
isa
=>
'Koha::Contrib::Tamil::Koha'
);
sub
BUILD {
my
$self
=
shift
;
print
__
"Starting Koha Indexer Daemon"
,
"\n"
;
$self
->koha(
$self
->conf
? Koha::Contrib::Tamil::Koha->new(
conf_file
=>
$self
->conf)
: Koha::Contrib::Tamil::Koha->new() );
$self
->name(
$self
->koha->conf->{config}->{database} );
my
$idle
= AnyEvent->timer(
after
=>
$self
->timeout,
interval
=>
$self
->timeout,
cb
=>
sub
{
$self
->index_zebraqueue(); }
);
AnyEvent->condvar->
recv
;
}
sub
index_zebraqueue {
my
$self
=
shift
;
my
$sql
= " SELECT COUNT(*), server
FROM zebraqueue
WHERE done = 0
GROUP BY server ";
my
$sth
=
$self
->koha->dbh->prepare(
$sql
);
$sth
->execute();
my
%count
= (
biblio
=> 0,
authority
=> 0 );
while
(
my
(
$count
,
$server
) =
$sth
->fetchrow ) {
$server
=~ s/server//g;
$count
{
$server
} =
$count
;
}
print
__x (
"[{name}] Index biblio ({biblio_count}) authority ({auth_count})"
,
name
=>
$self
->name,
biblio_count
=>
$count
{biblio},
auth_count
=>
$count
{authority} ),
"\n"
;
for
my
$source
(
qw/biblio authority/
) {
next
unless
$count
{
$source
};
my
$indexer
= Koha::Contrib::Tamil::Indexer->new(
koha
=>
$self
->koha,
source
=>
$source
,
select
=>
'queue'
,
blocking
=> 1,
verbose
=>
$self
->verbose,
);
$indexer
->directory(
$self
->directory)
if
$self
->directory;
$indexer
->run();
}
}
no
Moose;
__PACKAGE__->meta->make_immutable;
1;