Bugzilla – Attachment 135935 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) Record and use context in background_jobs
Bug-30889-follow-up-Record-and-use-context-in-back.patch (text/plain), 3.35 KB, created by
Martin Renvoize (ashimema)
on 2022-06-10 13:24:08 UTC
(
hide
)
Description:
Bug 30889: (follow-up) Record and use context in background_jobs
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2022-06-10 13:24:08 UTC
Size:
3.35 KB
patch
obsolete
>From 28957bd99b3ce101444b611317962ed27c0b7f87 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Fri, 10 Jun 2022 14:09:21 +0100 >Subject: [PATCH] Bug 30889: (follow-up) Record and use context in > background_jobs > >This patch records the current context to the background_jobs table at >enqueue time and then uses that record to set the context at process >time. >--- > Koha/BackgroundJob.pm | 25 +++++++++++++++++++++---- > misc/background_jobs_worker.pl | 16 +--------------- > 2 files changed, 22 insertions(+), 19 deletions(-) > >diff --git a/Koha/BackgroundJob.pm b/Koha/BackgroundJob.pm >index 517c54f010..97b1bd7cbc 100644 >--- a/Koha/BackgroundJob.pm >+++ b/Koha/BackgroundJob.pm >@@ -96,12 +96,15 @@ Return the job_id of the newly created job. > sub enqueue { > my ( $self, $params ) = @_; > >- my $job_type = $self->job_type; >- my $job_size = $params->{job_size}; >- my $job_args = $params->{job_args}; >- my $job_queue = $params->{job_queue} // 'default'; >+ my $job_type = $self->job_type; >+ my $job_size = $params->{job_size}; >+ my $job_args = $params->{job_args}; >+ my $job_context = $params->{job_context} // C4::Context->userenv; >+ my $job_queue = $params->{job_queue} // 'default'; > > my $borrowernumber = (C4::Context->userenv) ? C4::Context->userenv->{number} : undef; >+ $job_context->{interface} = C4::Context->interface; >+ my $json_context = encode_json $job_context; > my $json_args = encode_json $job_args; > > $self->set( >@@ -111,6 +114,7 @@ sub enqueue { > queue => $job_queue, > size => $job_size, > data => $json_args, >+ context => $json_context, > enqueued_on => dt_from_string, > borrowernumber => $borrowernumber, > } >@@ -162,6 +166,19 @@ 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} >+ ); >+ > return $derived_class->process( $args ); > } > >diff --git a/misc/background_jobs_worker.pl b/misc/background_jobs_worker.pl >index fd164c18e6..0d9d7e2d1d 100755 >--- a/misc/background_jobs_worker.pl >+++ b/misc/background_jobs_worker.pl >@@ -121,21 +121,7 @@ sub process_job { > > die "fork failed!" unless defined $pid; > >- my $patron = Koha::Patrons->find($job->borrowernumber); >- if ( $patron ) { >- C4::Context->_new_userenv(-1); >- C4::Context->interface('intranet'); >- C4::Context->set_userenv( >- $patron->borrowernumber, $patron->userid, >- $patron->cardnumber, $patron->firstname, >- $patron->surname, $patron->branchcode, >- $patron->library->branchname, $patron->flags >- ); >- $job->process( $args ); >- C4::Context->_unset_userenv(-1); >- } ese { >- $job->process( $args ); >- } >+ $job->process( $args ); > > exit; > } >-- >2.20.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