Tamil/IndexerDaemon.pm untested

filter: Statementstmt 0.0% 0 / 56 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 74 CC 4 SCAR 15.9
CC
4
Cov
0%
index_zebraqueue
12.0
BUILD
6.0
BEGIN
2.0
CRAP 4.9
1 package Koha::Contrib::Tamil::IndexerDaemon;
2 # ABSTRACT: Class implementing a Koha records indexer daemon
3 $Koha::Contrib::Tamil::IndexerDaemon::VERSION = '0.074';
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__