| 1 | package Koha::Contrib::Tamil::IndexerDaemon; | ||
| 2 | # ABSTRACT: Class implementing a Koha records indexer daemon | ||
| 3 | $Koha::Contrib::Tamil::IndexerDaemon::VERSION = '0.072'; | ||
| 4 | use Moose; | ||
| 5 | |||
| 6 | use 5.010; | ||
| 7 | use utf8; | ||
| 8 | use AnyEvent; | ||
| 9 | use Koha::Contrib::Tamil::Koha; | ||
| 10 | use Koha::Contrib::Tamil::Indexer; | ||
| 11 | use Locale::TextDomain ('Koha-Contrib-Tamil'); | ||
| 12 | |||
| 13 | with 'MooseX::Getopt'; | ||
| 14 | |||
| 15 | |||
| 16 | has name => ( is => 'rw', isa => 'Str' ); | ||
| 17 | |||
| 18 | |||
| 19 | |||
| 20 | has conf => ( is => 'rw', isa => 'Str' ); | ||
| 21 | |||
| 22 | |||
| 23 | |||
| 24 | has directory => ( is => 'rw', isa => 'Str' ); | ||
| 25 | |||
| 26 | |||
| 27 | |||
| 28 | has timeout => ( | ||
| 29 | is => 'rw', | ||
| 30 | isa => 'Int', | ||
| 31 | default => 60, | ||
| 32 | ); | ||
| 33 | |||
| 34 | |||
| 35 | |||
| 36 | has verbose => ( is => 'rw', isa => 'Bool', default => 0 ); | ||
| 37 | |||
| 38 | has koha => ( is => 'rw', isa => 'Koha::Contrib::Tamil::Koha' ); | ||
| 39 | |||
| 40 | |||
| 41 | sub BUILD { | ||
| 42 | my $self = shift; | ||
| 43 | |||
| 44 | print __"Starting Koha Indexer Daemon", "\n"; | ||
| 45 | |||
| 46 | $self->koha( $self->conf | ||
| 47 | ? Koha::Contrib::Tamil::Koha->new(conf_file => $self->conf) | ||
| 48 | : Koha::Contrib::Tamil::Koha->new() ); | ||
| 49 | $self->name( $self->koha->conf->{config}->{database} ); | ||
| 50 | |||
| 51 | my $idle = AnyEvent->timer( | ||
| 52 | after => $self->timeout, | ||
| 53 | interval => $self->timeout, | ||
| 54 | cb => sub { $self->index_zebraqueue(); } | ||
| 55 | ); | ||
| 56 | AnyEvent->condvar->recv; | ||
| 57 | } | ||
| 58 | |||
| 59 | |||
| 60 | sub index_zebraqueue { | ||
| 61 | my $self = shift; | ||
| 62 | |||
| 63 | my $sql = " SELECT COUNT(*), server | ||
| 64 | FROM zebraqueue | ||
| 65 | WHERE done = 0 | ||
| 66 | GROUP BY server "; | ||
| 67 | my $sth = $self->koha->dbh->prepare($sql); | ||
| 68 | $sth->execute(); | ||
| 69 | my %count = ( biblio => 0, authority => 0 ); | ||
| 70 | while ( my ($count, $server) = $sth->fetchrow ) { | ||
| 71 | $server =~ s/server//g; | ||
| 72 | $count{$server} = $count; | ||
| 73 | } | ||
| 74 | |||
| 75 | print __x ( | ||
| 76 | "[{name}] Index biblio ({biblio_count}) authority ({auth_count})", | ||
| 77 | name => $self->name, | ||
| 78 | biblio_count => $count{biblio}, | ||
| 79 | auth_count => $count{authority} ), "\n"; | ||
| 80 | |||
| 81 | for my $source (qw/biblio authority/) { | ||
| 82 | next unless $count{$source}; | ||
| 83 | my $indexer = Koha::Contrib::Tamil::Indexer->new( | ||
| 84 | koha => $self->koha, | ||
| 85 | source => $source, | ||
| 86 | select => 'queue', | ||
| 87 | blocking => 1, | ||
| 88 | keep => 1, | ||
| 89 | verbose => $self->verbose, | ||
| 90 | ); | ||
| 91 | $indexer->directory($self->directory) if $self->directory; | ||
| 92 | $indexer->run(); | ||
| 93 | } | ||
| 94 | } | ||
| 95 | |||
| 96 | no Moose; | ||
| 97 | __PACKAGE__->meta->make_immutable; | ||
| 98 | 1; | ||
| 99 | |||
| 100 | __END__ | ||
| 101 | |||
| 102 | =pod | ||
| 103 | |||
| 104 | =encoding UTF-8 | ||
| 105 | |||
| 106 | =head1 NAME | ||
| 107 | |||
| 108 | Koha::Contrib::Tamil::IndexerDaemon - Class implementing a Koha records indexer daemon | ||
| 109 | |||
| 110 | =head1 VERSION | ||
| 111 | |||
| 112 | version 0.072 | ||
| 113 | |||
| 114 | =head1 SYNOPSIS | ||
| 115 | |||
| 116 | # Index Koha queued biblio/authority records every minute. | ||
| 117 | # KOHA_CONF environment variable is used to find which Koha | ||
| 118 | # instance to use. | ||
| 119 | # Records are exported from Koha DB into files located in | ||
| 120 | # the current directory | ||
| 121 | my $daemon = Koha::Contrib::Tamil::IndexerDaemon->new(); | ||
| 122 | |||
| 123 | my $daemon = Koha::Contrib::Tamil::IndexerDaemon->new( | ||
| 124 | timeout => 20, | ||
| 125 | conf => '/home/koha/mylib/etc/koha-conf.xml', | ||
| 126 | directory => '/home/koha/mylib/tmp', | ||
| 127 | verbose => 1 ); | ||
| 128 | |||
| 129 | =head1 ATTRIBUTES | ||
| 130 | |||
| 131 | =head2 conf($file_name) | ||
| 132 | |||
| 133 | Koha configuration file name. If not supplied, KOHA_CONF environment variable | ||
| 134 | is used to locate the configuration file. | ||
| 135 | |||
| 136 | =head2 directory($directory_name) | ||
| 137 | |||
| 138 | Location of the directory where to export biblio/authority records before | ||
| 139 | sending them to Zebra indexer. | ||
| 140 | |||
| 141 | =head2 timeout($seconds) | ||
| 142 | |||
| 143 | Number of seconds between indexing. | ||
| 144 | |||
| 145 | =head2 verbose(0|1) | ||
| 146 | |||
| 147 | Task verbosity. | ||
| 148 | |||
| 149 | =head1 AUTHOR | ||
| 150 | |||
| 151 | Frédéric Demians <f.demians@tamil.fr> | ||
| 152 | |||
| 153 | =head1 COPYRIGHT AND LICENSE | ||
| 154 | |||
| 155 | This software is Copyright (c) 2023 by Fréderic Démians. | ||
| 156 | |||
| 157 | This is free software, licensed under: | ||
| 158 | |||
| 159 | The GNU General Public License, Version 3, June 2007 | ||
| 160 | |||
| 161 | =cut |