Bug 32894: Koha::Biblio->biblioitem
[koha.git] / Koha / BackgroundJob / UpdateElasticIndex.pm
1 package Koha::BackgroundJob::UpdateElasticIndex;
2
3 # This file is part of Koha.
4 #
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.
9 #
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.
14 #
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>.
17
18 use Modern::Perl;
19
20 use Koha::SearchEngine;
21 use Koha::SearchEngine::Indexer;
22
23 use base 'Koha::BackgroundJob';
24
25 =head1 NAME
26
27 Koha::BackgroundJob::UpdateElasticIndex - Update Elastic index
28
29 This is a subclass of Koha::BackgroundJob.
30
31 While most background jobs provide a I<process> method, the ES indexing has its
32 own dedicated worker: misc/workers/es_indexer_daemon.pl
33
34 That worker handles all job processing.
35
36 =head1 API
37
38 =head2 Class methods
39
40 =head3 job_type
41
42 Define the job type of this job: update_elastic_index
43
44 =cut
45
46 sub job_type {
47     return 'update_elastic_index';
48 }
49
50 =head3 enqueue
51
52 Enqueue the new job
53
54 =cut
55
56 sub enqueue {
57     my ( $self, $args) = @_;
58
59     return unless exists $args->{record_server};
60     return unless exists $args->{record_ids};
61
62     my $record_server = $args->{record_server};
63     my @record_ids = @{ $args->{record_ids} };
64     # elastic_index queue will be handled by the es_indexer_daemon script
65
66     $self->SUPER::enqueue({
67         job_size => 1, # Each index is a single job, regardless of the amount of records included
68         job_args => {record_server => $record_server, record_ids => \@record_ids},
69         job_queue => 'elastic_index'
70     });
71 }
72
73 1;