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(
81 report_info_callback => sub { $self->report_info(@_); },
82 step_callback => sub { $self->step; },
83 set_size_callback => sub { $self->set_job_size(@_); },
84 add_message_callback => sub { $self->add_message(@_); },
90 report_type => $ud_provider->{report_type},
91 total_records => $ud_provider->{total_records},
92 us_report_info => $self->{us_report_info},
93 ud_provider_id => $ud_provider->erm_usage_data_provider_id,
94 ud_provider_name => $ud_provider->name,
97 my $data = $self->decoded_data;
98 $data->{report} = $report;
99 $data->{messages} = \@{ $self->{messages} };
101 $self->finish($data);
106 Setter for report_info
111 my ( $self, $info ) = @_;
113 $self->{us_report_info}{$info}++;
123 my ( $self, $size ) = @_;
125 $self->size($size)->store();
132 type => 'success', # success, warning or error
133 code => 'object_added', # object_added or object_already_exists
134 title => $row->{Title},
138 Add a new job message
143 my ( $self, $message ) = @_;
145 push @{ $self->{messages} }, $message;
156 my ( $self, $args ) = @_;
158 $self->SUPER::enqueue(
161 job_args => {%$args},
162 job_queue => 'long_tasks',