Bugzilla – Attachment 133992 Details for
Bug 29346
Real-time holds queue update
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29346: Add holds queue update background job
Bug-29346-Add-holds-queue-update-background-job.patch (text/plain), 6.19 KB, created by
Tomás Cohen Arazi
on 2022-04-26 19:38:52 UTC
(
hide
)
Description:
Bug 29346: Add holds queue update background job
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi
Created:
2022-04-26 19:38:52 UTC
Size:
6.19 KB
patch
obsolete
>From 25ac73680a14fb97ce20c3eddb3b7a86006bd45e Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 24 Feb 2022 08:46:20 -0300 >Subject: [PATCH] Bug 29346: Add holds queue update background job > >This patch adds a background job that takes care of updating the holds >queue rows for a given list of biblios. > >It is designed to be used for real-time batch updating the holds queue >when required. Tasks would be added by the relevant methods under the >right use cases. > >Sponsored-by: Montgomery County Public Libraries >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > Koha/BackgroundJob.pm | 1 + > .../BatchUpdateBiblioHoldsQueue.pm | 180 ++++++++++++++++++ > 2 files changed, 181 insertions(+) > create mode 100644 Koha/BackgroundJob/BatchUpdateBiblioHoldsQueue.pm > >diff --git a/Koha/BackgroundJob.pm b/Koha/BackgroundJob.pm >index c661746d7d7..e754bc7aa76 100644 >--- a/Koha/BackgroundJob.pm >+++ b/Koha/BackgroundJob.pm >@@ -284,6 +284,7 @@ sub core_types_to_classes { > batch_item_record_deletion => 'Koha::BackgroundJob::BatchDeleteItem', > batch_item_record_modification => 'Koha::BackgroundJob::BatchUpdateItem', > batch_hold_cancel => 'Koha::BackgroundJob::BatchCancelHold', >+ update_holds_queue_for_biblios => 'Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue', > }; > } > >diff --git a/Koha/BackgroundJob/BatchUpdateBiblioHoldsQueue.pm b/Koha/BackgroundJob/BatchUpdateBiblioHoldsQueue.pm >new file mode 100644 >index 00000000000..1909b637311 >--- /dev/null >+++ b/Koha/BackgroundJob/BatchUpdateBiblioHoldsQueue.pm >@@ -0,0 +1,180 @@ >+package Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue; >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use JSON qw( encode_json decode_json ); >+use Try::Tiny; >+ >+use Koha::Exceptions; >+ >+use C4::HoldsQueue >+ qw(load_branches_to_pull_from TransportCostMatrix update_queue_for_biblio); >+ >+use base 'Koha::BackgroundJob'; >+ >+=head1 NAME >+ >+Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue - Update the holds queue >+for a specified list of biblios. >+ >+This is a subclass of Koha::BackgroundJob. >+ >+=head1 API >+ >+=head2 Class methods >+ >+=head3 job_type >+ >+Returns a string representing the job type. In this case I<update_holds_queue_for_biblios>. >+ >+=cut >+ >+sub job_type { >+ return 'update_holds_queue_for_biblios'; >+} >+ >+=head3 process >+ >+Perform the expected action. >+ >+=cut >+ >+sub process { >+ my ( $self, $args ) = @_; >+ >+ my $schema = Koha::Database->new->schema; >+ >+ my $job_progress = 0; >+ >+ $self->set( >+ { >+ started_on => \'NOW()', >+ progress => $job_progress, >+ status => 'started', >+ } >+ )->store; >+ >+ my @biblio_ids = @{ $args->{biblio_id} }; >+ >+ my $report = { >+ total_biblios => scalar @biblio_ids, >+ total_success => 0, >+ }; >+ >+ my $use_transport_cost_matrix = C4::Context->preference("UseTransportCostMatrix"); >+ my $transport_cost_matrix = $use_transport_cost_matrix ? TransportCostMatrix() : undef; >+ my $branches_to_use = load_branches_to_pull_from($use_transport_cost_matrix); >+ >+ my @messages; >+ >+ foreach my $biblio_id (@biblio_ids) { >+ try { >+ >+ $schema->storage->txn_begin; >+ >+ my $result = update_queue_for_biblio( >+ { >+ biblio_id => $biblio_id, >+ branches_to_use => $branches_to_use, >+ delete => 1, >+ transport_cost_matrix => $transport_cost_matrix >+ } >+ ); >+ push @messages, >+ { >+ type => 'success', >+ code => 'holds_queue_updated', >+ biblio_id => $biblio_id, >+ availabe_items => $result->{available_items}, >+ mapped_items => $result->{mapped_items}, >+ requests => $result->{requests}, >+ }; >+ $report->{total_success}++; >+ >+ $schema->storage->txn_commit; >+ } >+ catch { >+ push @messages, { >+ type => 'error', >+ code => 'holds_queue_update_error', >+ biblio_id => $biblio_id, >+ error => "$_", >+ }; >+ >+ $schema->storage->txn_rollback; >+ }; >+ >+ $self->progress( $job_progress++ )->store; >+ } >+ >+ my $job_data = decode_json $self->data; >+ $job_data->{messages} = \@messages; >+ $job_data->{report} = $report; >+ >+ $self->set( >+ { >+ ended_on => \'NOW()', >+ data => encode_json $job_data, >+ } >+ ); >+ $self->status('finished') >+ unless $self->status ne 'cancelled'; >+ >+ $self->store; >+} >+ >+=head3 enqueue >+ >+Enqueue the new job >+ >+=cut >+ >+sub enqueue { >+ my ( $self, $args ) = @_; >+ >+ Koha::Exceptions::MissingParameter->throw( >+ "Missing biblio_ids parameter is mandatory") >+ unless exists $args->{biblio_ids}; >+ >+ my @biblio_ids = @{ $args->{biblio_ids} }; >+ >+ $self->SUPER::enqueue( >+ { >+ job_size => scalar @biblio_ids, >+ job_args => { biblio_ids => \@biblio_ids } >+ } >+ ); >+} >+ >+=head3 additional_report >+ >+Pass the biblio's title and patron's name >+ >+=cut >+ >+sub additional_report { >+ my ( $self, $args ) = @_; >+ >+ my $messages = $self->messages; >+ for my $m (@$messages) { >+ $m->{biblio} = Koha::Biblios->find( $m->{biblio_id} ); >+ } >+ return { report_messages => $messages }; >+} >+ >+1; >-- >2.36.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 29346
:
131088
|
131089
|
131811
|
131812
|
131813
|
131815
|
132078
|
132079
|
132080
|
132081
|
132082
|
132083
|
133183
|
133184
|
133185
|
133186
|
133187
|
133188
|
133189
|
133190
|
133191
|
133205
|
133991
|
133992
|
133993
|
133994
|
133995
|
133996
|
133997
|
133998
|
133999
|
134000
|
134001
|
134010
|
134225
|
134227
|
134309
|
134310
|
134311
|
134312
|
134313
|
134314
|
134315
|
134316
|
134317
|
134318
|
134319
|
134320
|
134321
|
134322
|
134328
|
134329
|
134330
|
134331
|
134332
|
134333
|
134334
|
134335
|
134336
|
134337
|
134338
|
134339
|
134340
|
134341
|
134342
|
134343