Bugzilla – Attachment 145082 Details for
Bug 32481
Rabbit times out when too many jobs are queued and the response takes too long
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Test background jobs
Test-background-jobs.patch (text/plain), 4.80 KB, created by
Jonathan Druart
on 2023-01-06 14:48:52 UTC
(
hide
)
Description:
Test background jobs
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2023-01-06 14:48:52 UTC
Size:
4.80 KB
patch
obsolete
>From 33b40618af3ac05673eedc2fc8ebe861b4b05d9f Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Fri, 6 Jan 2023 15:45:49 +0100 >Subject: [PATCH] Test background jobs > >https://bugs.koha-community.org/show_bug.cgi?id=32481 >--- > Koha/BackgroundJob/Test.pm | 44 ++++++++++++++++++++++++++++++++++ > misc/background_jobs_worker.pl | 39 ++++++++++-------------------- > test_bg.pl | 30 +++++++++++++++++++++++ > 3 files changed, 87 insertions(+), 26 deletions(-) > create mode 100644 Koha/BackgroundJob/Test.pm > create mode 100644 test_bg.pl > >diff --git a/Koha/BackgroundJob/Test.pm b/Koha/BackgroundJob/Test.pm >new file mode 100644 >index 00000000000..93b6d9e4243 >--- /dev/null >+++ b/Koha/BackgroundJob/Test.pm >@@ -0,0 +1,44 @@ >+package Koha::BackgroundJob::Test; >+ >+# 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 base 'Koha::BackgroundJob'; >+ >+sub job_type { >+ return 'test'; >+} >+ >+sub process { >+ my ( $self ) = @_; >+ >+ warn "Starting " . $self->id; >+ $self->start; >+ sleep 1; >+ $self->finish; >+} >+ >+sub enqueue { >+ my ( $self ) = @_; >+ >+ $self->SUPER::enqueue({ >+ job_size => 1, >+ job_args => {}, >+ }); >+} >+ >+1; >diff --git a/misc/background_jobs_worker.pl b/misc/background_jobs_worker.pl >index eb36f34f964..16eb99ec067 100755 >--- a/misc/background_jobs_worker.pl >+++ b/misc/background_jobs_worker.pl >@@ -78,7 +78,11 @@ if ( $conn ) { > # FIXME cf note in Koha::BackgroundJob about $namespace > my $namespace = C4::Context->config('memcached_namespace'); > for my $queue (@queues) { >- $conn->subscribe({ destination => sprintf("/queue/%s-%s", $namespace, $queue), ack => 'client' }); >+ $conn->subscribe({ >+ destination => sprintf("/queue/%s-%s", $namespace, $queue), >+ ack => 'client', >+ 'activemq.prefetchSize' => 1, >+ }); > } > } > while (1) { >@@ -90,38 +94,21 @@ while (1) { > } > > my $body = $frame->body; >+ warn "GOT $body"; > my $args = decode_json($body); # TODO Should this be from_json? Check utf8 flag. > >+ $conn->ack( { frame => $frame } ); # FIXME depending on success? >+ > # FIXME This means we need to have create the DB entry before > # It could work in a first step, but then we will want to handle job that will be created from the message received > my $job = Koha::BackgroundJobs->find($args->{job_id}); > >- process_job( $job, $args ); >- $conn->ack( { frame => $frame } ); # FIXME depending on success? >+ warn "Starting " . $args->{job_id}; >+ $job->start; >+ sleep 1; >+ warn "Finishing" . $args->{job_id}; >+ $job->finish; > >- } else { >- my $jobs = Koha::BackgroundJobs->search({ status => 'new', queue => \@queues }); >- while ( my $job = $jobs->next ) { >- my $args = $job->json->decode($job->data); >- process_job( $job, { job_id => $job->id, %$args } ); >- } >- sleep 10; > } > } > $conn->disconnect; >- >-sub process_job { >- my ( $job, $args ) = @_; >- >- my $pid; >- if ( $pid = fork ) { >- wait; >- return; >- } >- >- die "fork failed!" unless defined $pid; >- >- $job->process( $args ); >- >- exit; >-} >diff --git a/test_bg.pl b/test_bg.pl >new file mode 100644 >index 00000000000..695752a6566 >--- /dev/null >+++ b/test_bg.pl >@@ -0,0 +1,30 @@ >+use Modern::Perl; >+use Koha::BackgroundJob::Test; >+use Koha::BackgroundJobs; >+my @job_ids; >+for my $i ( 1 .. 100 ) { >+ my $job = Koha::BackgroundJob::Test->new; >+ $job->enqueue; >+ push @job_ids, $job->id; >+} >+ >+while ( 1 ) { >+ my $jobs = Koha::BackgroundJobs->search({id => \@job_ids}, { order_by => 'id' }); >+ my $last_status; >+ while ( my $j = $jobs->next ) { >+ my $s = $j->status; >+ my $ss = '?'; >+ if ( $s eq 'new' ) { >+ $ss = "\e[1;31m;"; >+ print sprintf("\e[1;31m;%s\e[0m", $j->id); >+ } elsif ( $s eq 'started' ) { >+ print sprintf("\e[1;32m;%s\e[0m", $j->id); >+ } elsif ( $s eq 'finished' ) { >+ print sprintf("\e[1;33m;%s\e[0m", $j->id); >+ } >+ $last_status = $s; >+ } >+ print "\n"; >+ sleep 1; >+ last if $last_status eq 'finished'; >+} >-- >2.25.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 32481
:
144809
|
145082
|
145134
|
145173
|
145208