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::EUsage::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} = {
68 added_usage_objects => 0,
71 # FIXME If the job has already been started, but started again (worker has been restart for instance)
72 # Then we will start from scratch and so double process the same records
76 my $ud_provider = Koha::ERM::EUsage::UsageDataProviders->find( $args->{ud_provider_id} );
78 $ud_provider->set_background_job_callbacks(
80 report_info_callback => sub { $self->report_info(@_); },
81 step_callback => sub { $self->step; },
82 set_size_callback => sub { $self->set_job_size(@_); },
83 add_message_callback => sub { $self->add_message(@_); },
88 if ( $args->{file_content} ) {
89 my $counter_files_rs = $ud_provider->counter_files(
92 usage_data_provider_id => $ud_provider->erm_usage_data_provider_id,
93 file_content => $args->{file_content},
94 date_uploaded => POSIX::strftime( "%Y%m%d%H%M%S", localtime ),
95 filename => $ud_provider->name . "_" . $ud_provider->{report_type},
99 $counter_file = $counter_files_rs->last;
101 $ud_provider->harvest_sushi(
103 begin_date => $args->{begin_date},
104 end_date => $args->{end_date},
105 report_type => $args->{report_type}
110 my $job_report_report_type = $ud_provider->{report_type} || $counter_file->type;
114 report_type => $job_report_report_type,
115 us_report_info => $self->{us_report_info},
116 ud_provider_id => $ud_provider->erm_usage_data_provider_id,
117 ud_provider_name => $ud_provider->name,
120 my $data = $self->decoded_data;
121 $data->{report} = $report;
122 $data->{messages} = \@{ $self->{messages} };
124 $self->finish($data);
129 Setter for report_info
134 my ( $self, $info ) = @_;
136 $self->{us_report_info}{$info}++;
146 my ( $self, $size ) = @_;
148 $self->size($size)->store();
155 type => 'success', # success, warning or error
156 code => 'object_added', # object_added or object_already_exists
157 title => $row->{Title},
158 message => 'message',
162 Add a new job message
167 my ( $self, $message ) = @_;
169 push @{ $self->{messages} }, $message;
180 my ( $self, $args ) = @_;
182 $self->SUPER::enqueue(
185 job_args => {%$args},
186 job_queue => 'long_tasks',