1 package Koha::BackgroundJob::ErmSushiHarvester;
3 # This file is part of Koha.
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>.
22 use Koha::DateUtils qw( dt_from_string );
23 use Koha::ERM::UsageDataProviders;
25 use base 'Koha::BackgroundJob';
29 Koha::BackgroundJob::ErmSushiHarvester - Background job derived class to process the ERM Usage Statistics SUSHI Harvester
36 Define the job type of this job: erm_sushi_harvester
41 return 'erm_sushi_harvester';
46 Koha::BackgroundJob->find($id)->process(
48 ud_provider_id => $self->erm_usage_data_provider_id
52 Process the harvesting.
57 my ( $self, $args ) = @_;
59 if ( $self->status eq 'cancelled' ) {
63 $self->{us_report_info} = {
70 # FIXME If the job has already been started, but started again (worker has been restart for instance)
71 # Then we will start from scratch and so double process the same records
76 Koha::ERM::UsageDataProviders->find( $args->{ud_provider_id} );
78 $ud_provider->harvest(
83 report_info_callback => sub { $self->report_info(@_); },
84 step_callback => sub { $self->step; },
85 set_size_callback => sub { $self->set_job_size(@_); },
86 add_message_callback => sub { $self->add_message(@_); },
92 report_type => $ud_provider->{report_type},
93 total_records => $ud_provider->{total_records},
94 us_report_info => $self->{us_report_info},
95 ud_provider_id => $ud_provider->erm_usage_data_provider_id,
96 ud_provider_name => $ud_provider->name,
99 my $data = $self->decoded_data;
100 $data->{report} = $report;
101 $data->{messages} = \@{ $self->{messages} };
103 $self->finish($data);
108 Setter for report_info
113 my ( $self, $info ) = @_;
115 $self->{us_report_info}{$info}++;
125 my ( $self, $size ) = @_;
127 $self->size($size)->store();
134 type => 'success', # success, warning or error
135 code => 'object_added', # object_added or object_already_exists
136 title => $row->{Title},
140 Add a new job message
145 my ( $self, $message ) = @_;
147 push @{ $self->{messages} }, $message;
158 my ( $self, $args ) = @_;
160 $self->SUPER::enqueue(
163 job_args => {%$args},
164 job_queue => 'long_tasks',