1 # This file is part of Koha.
3 # Copyright (C) 2013 Tamil s.a.r.l.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
18 package Koha::Indexer::Daemon;
25 use Koha::Indexer::Indexing;
28 with 'MooseX::Getopt';
31 has name => ( is => 'rw', isa => 'Str' );
33 has directory => ( is => 'rw', isa => 'Str' );
41 has verbose => ( is => 'rw', isa => 'Bool', default => 0 );
47 say "Starting Koha Indexer Daemon";
49 $self->name( C4::Context->config('database') );
51 my $idle = AnyEvent->timer(
52 after => $self->timeout,
53 interval => $self->timeout,
54 cb => sub { $self->index_zebraqueue(); }
56 AnyEvent->condvar->recv;
60 sub index_zebraqueue {
63 my $dbh = C4::Context->dbh();
64 my $sql = " SELECT COUNT(*), server
68 my $sth = $dbh->prepare($sql);
70 my %count = ( biblio => 0, authority => 0 );
71 while ( my ($count, $server) = $sth->fetchrow ) {
72 $server =~ s/server//g;
73 $count{$server} = $count;
76 say "[", $self->name, "] Index biblio (", $count{biblio}, ") authority (",
77 $count{authority}, ")";
79 for my $source (qw/biblio authority/) {
80 next unless $count{$source};
81 my $indexer = Koha::Indexer::Indexing->new(
86 verbose => $self->verbose,
88 $indexer->directory($self->directory) if $self->directory;
94 __PACKAGE__->meta->make_immutable;
102 # Index Koha queued biblio/authority records every minute.
103 # KOHA_CONF environment variable is used to find which Koha
105 # Records are exported from Koha DB into files located in
106 # the current directory
107 my $daemon = Koha::Indexer::Daemon->new();
109 my $daemon = Koha::Indexer::Daemon->new(
111 directory => '/home/koha/mylib/tmp',
118 =item directory($directory_name)
120 Location of the directory where to export biblio/authority records before
121 sending them to Zebra indexer.
123 =item timeout($seconds)
125 Number of seconds between indexing.