Bug 29346: Add better reporting

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Tomas Cohen Arazi 2022-04-28 10:57:04 -03:00 committed by Fridolin Somers
parent db49180e1d
commit 4708933800
3 changed files with 52 additions and 14 deletions

View File

@ -20,6 +20,7 @@ use Modern::Perl;
use JSON qw( encode_json decode_json );
use Try::Tiny;
use Koha::Biblios;
use Koha::Exceptions;
use C4::HoldsQueue
@ -59,12 +60,10 @@ sub process {
my $schema = Koha::Database->new->schema;
my $job_progress = 0;
$self->set(
{
started_on => \'NOW()',
progress => $job_progress,
progress => 0,
status => 'started',
}
)->store;
@ -100,26 +99,25 @@ sub process {
type => 'success',
code => 'holds_queue_updated',
biblio_id => $biblio_id,
available_items => $result->{available_items},
mapped_items => $result->{mapped_items},
requests => $result->{requests},
};
$report->{total_success}++;
$schema->storage->txn_commit;
}
catch {
push @messages, {
push @messages,
{
type => 'error',
code => 'holds_queue_update_error',
biblio_id => $biblio_id,
error => "$_",
};
};
$schema->storage->txn_rollback;
};
$self->progress( $job_progress++ )->store;
$self->progress( $self->progress + 1 )->store;
}
my $job_data = decode_json $self->data;
@ -130,12 +128,9 @@ sub process {
{
ended_on => \'NOW()',
data => encode_json $job_data,
status => 'finished',
}
);
$self->status('finished')
unless $self->status ne 'cancelled';
$self->store;
)->store;
}
=head3 enqueue

View File

@ -0,0 +1,41 @@
[% USE KohaSpan %]
[% BLOCK report %]
[% SET report = job.report %]
[% IF report %]
[% IF report.total_biblios == report.total_success %]
<div class="dialog message">
Holds queue successfully updated.
</div>
[% ELSE %]
<div class="dialog message">
<span>Holds queue for [% report.total_success | html %] / [% report.total_biblios | html %] has been successfully updated. Some errors occurred.</span>
[% IF job.status == 'cancelled' %]<span>The job has been cancelled before it finished.</span>[% END %]
</div>
[% END %]
[% END %]
[% END %]
[% BLOCK detail %]
[% FOR m IN report_messages %]
<div class="dialog message">
[% IF m.type == 'success' %]
<i class="fa fa-check success"></i>
[% ELSIF m.type == 'warning' %]
<i class="fa fa-warning warn"></i>
[% ELSIF m.type == 'error' %]
<i class="fa fa-exclamation error"></i>
[% END %]
[% SWITCH m.code %]
[% CASE 'holds_queue_update_error' %]
[% IF m.biblio_id %]
<span>Holds queue for biblio <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% m.biblio_id | uri %]">[% m.biblio.title | html %]</a>.</span>
[% END %]
<span>An error occurred ([% m.error | html %])</span>
[% END %]
</div>
[% END %]
[% END %]
[% BLOCK js %]
[% END %]

View File

@ -39,6 +39,8 @@
<span>Batch hold cancellation</span>
[% CASE 'update_elastic_index' %]
<span>Update Elasticsearch index</span>
[% CASE 'update_holds_queue_for_biblios' %]
<span>Holds queue update</span>
[% CASE %]<span>Unknown job type '[% job_type | html %]'</span>
[% END %]