Bugzilla – Attachment 136948 Details for
Bug 30889
Background jobs lead to wrong/missing info in logs
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30889: (follow-up) Warn if context is not defined
Bug-30889-follow-up-Warn-if-context-is-not-defined.patch (text/plain), 3.68 KB, created by
Tomás Cohen Arazi (tcohen)
on 2022-07-01 14:14:18 UTC
(
hide
)
Description:
Bug 30889: (follow-up) Warn if context is not defined
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2022-07-01 14:14:18 UTC
Size:
3.68 KB
patch
obsolete
>From de90b39b4c8a77ea3a911cf611e406770de5cf26 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Fri, 1 Jul 2022 10:21:58 -0300 >Subject: [PATCH] Bug 30889: (follow-up) Warn if context is not defined > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > Koha/BackgroundJob.pm | 29 +++++++++++++++++------------ > t/db_dependent/Koha/BackgroundJob.t | 21 ++++++++++++++++++++- > 2 files changed, 37 insertions(+), 13 deletions(-) > >diff --git a/Koha/BackgroundJob.pm b/Koha/BackgroundJob.pm >index 97b1bd7cbc..76bed24426 100644 >--- a/Koha/BackgroundJob.pm >+++ b/Koha/BackgroundJob.pm >@@ -166,18 +166,23 @@ sub process { > > $args ||= {}; > >- my $context = decode_json($self->context); >- C4::Context->_new_userenv(-1); >- C4::Context->interface( $context->{interface} ); >- C4::Context->set_userenv( >- $context->{number}, $context->{id}, >- $context->{cardnumber}, $context->{firstname}, >- $context->{surname}, $context->{branch}, >- $context->{branchname}, $context->{flags}, >- $context->{emailaddress}, undef, >- $context->{desk_id}, $context->{desk_name}, >- $context->{register_id}, $context->{register_name} >- ); >+ if ( $self->context ) { >+ my $context = decode_json($self->context); >+ C4::Context->_new_userenv(-1); >+ C4::Context->interface( $context->{interface} ); >+ C4::Context->set_userenv( >+ $context->{number}, $context->{id}, >+ $context->{cardnumber}, $context->{firstname}, >+ $context->{surname}, $context->{branch}, >+ $context->{branchname}, $context->{flags}, >+ $context->{emailaddress}, undef, >+ $context->{desk_id}, $context->{desk_name}, >+ $context->{register_id}, $context->{register_name} >+ ); >+ } >+ else { >+ Koha::Logger->get->warn("A background job didn't have context defined (" . $self->id . ")"); >+ } > > return $derived_class->process( $args ); > } >diff --git a/t/db_dependent/Koha/BackgroundJob.t b/t/db_dependent/Koha/BackgroundJob.t >index 06b425bad1..2c368383f5 100755 >--- a/t/db_dependent/Koha/BackgroundJob.t >+++ b/t/db_dependent/Koha/BackgroundJob.t >@@ -28,9 +28,11 @@ use Koha::BackgroundJob::BatchUpdateItem; > use JSON qw( decode_json encode_json ); > > use t::lib::Mocks; >+use t::lib::Mocks::Logger; > use t::lib::TestBuilder; > use t::lib::Koha::BackgroundJob::BatchTest; > >+my $logger = t::lib::Mocks::Logger->new; > my $schema = Koha::Database->new->schema; > my $builder = t::lib::TestBuilder->new; > >@@ -176,7 +178,7 @@ subtest 'start(), step() and finish() tests' => sub { > > subtest 'process tests' => sub { > >- plan tests => 4; >+ plan tests => 5; > > $schema->storage->txn_begin; > >@@ -221,6 +223,23 @@ subtest 'process tests' => sub { > is_deeply( C4::Context->userenv, $job_context, "Userenv set from job context on process" ); > is_deeply( C4::Context->interface, 'intranet', "Interface set from job context on process" ); > >+ # Manually add a job (->new->store) without context >+ my $incomplete_job = t::lib::Koha::BackgroundJob::BatchTest->new( >+ { status => 'new', >+ size => 1, >+ borrowernumber => $patron->borrowernumber, >+ type => 'batch_test', >+ data => encode_json { >+ a => 'a', >+ b => 'b', >+ }, >+ } >+ )->store; >+ >+ $incomplete_job = Koha::BackgroundJobs->find( $incomplete_job->id ); >+ $incomplete_job->process(); >+ $logger->warn_is( "A background job didn't have context defined (" . $incomplete_job->id . ")" ); >+ > $schema->storage->txn_rollback; > }; > >-- >2.34.1
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 30889
:
135759
|
135760
|
135932
|
135933
|
135934
|
135935
|
135936
|
136294
|
136295
|
136296
|
136297
|
136298
|
136299
|
136375
|
136376
|
136784
|
136785
|
136786
|
136787
|
136788
|
136789
|
136790
|
136791
|
136792
|
136904
| 136948