Bugzilla – Attachment 139828 Details for
Bug 31453
Add ability to filter messages to process using process_message_queue.pl via a command line parameter
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 31453: Add ability to skip processing messages in message queue based on message contents
Bug-31453-Add-ability-to-skip-processing-messages-.patch (text/plain), 6.86 KB, created by
Kyle M Hall (khall)
on 2022-08-26 13:27:55 UTC
(
hide
)
Description:
Bug 31453: Add ability to skip processing messages in message queue based on message contents
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2022-08-26 13:27:55 UTC
Size:
6.86 KB
patch
obsolete
>From 91df2906bd5cc63d1cd1b14bd53d3c83ee4fd9a6 Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Wed, 24 Aug 2022 13:54:49 -0400 >Subject: [PATCH] Bug 31453: Add ability to skip processing messages in message > queue based on message contents > >It would be very useful to be able to tell process_message_queue.pl to skip processing some messages. This is particularly useful where a plugin handles sending some message using the before_send_messages hook, but while that plugin is processing, more messages meant for the plugin might be queued. At that point, control moves back to the script and SendQueuedMessages is called, and those messages end up being processed there instead of by the plugin. > >Test Plan: >1) Apply this patch >2) Queue two messages, each with a unique word >3) Run process_message_queue --content-not-like "WORD" > where WORD is a unique word in one of the two message >4) Note the message containing "WORD" was not processed >5) prove t/db_dependent/Letters.t >--- > C4/Letters.pm | 17 ++++--- > misc/cronjobs/process_message_queue.pl | 4 ++ > t/db_dependent/Letters.t | 63 +++++++++++++++++++++++++- > 3 files changed, 77 insertions(+), 7 deletions(-) > >diff --git a/C4/Letters.pm b/C4/Letters.pm >index 7c136f32f9..874a22605c 100644 >--- a/C4/Letters.pm >+++ b/C4/Letters.pm >@@ -971,12 +971,13 @@ Returns number of messages sent. > sub SendQueuedMessages { > my $params = shift; > >- my $which_unsent_messages = { >- 'message_id' => $params->{'message_id'}, >- 'limit' => $params->{'limit'} // 0, >- 'borrowernumber' => $params->{'borrowernumber'} // q{}, >- 'letter_code' => $params->{'letter_code'} // q{}, >- 'type' => $params->{'type'} // q{}, >+ my $which_unsent_messages = { >+ 'message_id' => $params->{'message_id'}, >+ 'limit' => $params->{'limit'} // 0, >+ 'borrowernumber' => $params->{'borrowernumber'} // q{}, >+ 'letter_code' => $params->{'letter_code'} // q{}, >+ 'type' => $params->{'type'} // q{}, >+ 'content_not_like' => $params->{'content_not_like'}, > }; > my $unsent_messages = _get_unsent_messages( $which_unsent_messages ); > MESSAGE: foreach my $message ( @$unsent_messages ) { >@@ -1274,6 +1275,10 @@ sub _get_unsent_messages { > $statement .= ' AND message_id = ?'; > push @query_params, $params->{message_id}; > } >+ if ( $params->{content_not_like} ) { >+ $statement .= ' AND content NOT LIKE ?'; >+ push @query_params, "%$params->{content_not_like}%"; >+ } > if ( $params->{'limit'} ) { > $statement .= ' limit ? '; > push @query_params, $params->{'limit'}; >diff --git a/misc/cronjobs/process_message_queue.pl b/misc/cronjobs/process_message_queue.pl >index d8918be607..002acc6059 100755 >--- a/misc/cronjobs/process_message_queue.pl >+++ b/misc/cronjobs/process_message_queue.pl >@@ -34,6 +34,7 @@ my $help = 0; > my $verbose = 0; > my $type = q{}; > my $letter_code; >+my $content_not_like; > > GetOptions( > 'u|username:s' => \$username, >@@ -44,6 +45,7 @@ GetOptions( > 'v|verbose' => \$verbose, > 't|type:s' => \$type, > 'c|code:s' => \$letter_code, >+ 'content-not-like:s'=> \$content_not_like, > ); > my $usage = << 'ENDUSAGE'; > >@@ -62,6 +64,7 @@ This script has the following parameters : > -m --method: authentication method required by SMTP server (See perldoc Sendmail.pm for supported authentication types.) > -h --help: this message > -v --verbose: provides verbose output to STDOUT >+ --content-not-like: Message will not be processed if it contains this value > ENDUSAGE > > die $usage if $help; >@@ -101,6 +104,7 @@ C4::Letters::SendQueuedMessages( > limit => $limit, > type => $type, > letter_code => $letter_code, >+ content_not_like => $content_not_like, > } > ); > >diff --git a/t/db_dependent/Letters.t b/t/db_dependent/Letters.t >index 426df4aea2..e773b46496 100755 >--- a/t/db_dependent/Letters.t >+++ b/t/db_dependent/Letters.t >@@ -18,7 +18,7 @@ > # along with Koha; if not, see <http://www.gnu.org/licenses>. > > use Modern::Perl; >-use Test::More tests => 85; >+use Test::More tests => 86; > use Test::MockModule; > use Test::Warn; > use Test::Exception; >@@ -905,6 +905,67 @@ EOF > is( $items_content, $expected_items_content, 'get_item_content should return correct items info without time (if dateonly => 1)' ); > }; > >+subtest 'Test content_not_like parameter for SendQueuedMessages' => sub { >+ plan tests => 1; >+ >+ my $dbh = C4::Context->dbh; >+ >+ my $borrowernumber = Koha::Patron->new({ >+ firstname => 'Jane', >+ surname => 'Smith', >+ categorycode => $patron_category, >+ branchcode => $library->{branchcode}, >+ dateofbirth => $date, >+ smsalertnumber => undef, >+ })->store->borrowernumber; >+ >+ $dbh->do(q|DELETE FROM message_queue|); >+ $my_message = { >+ 'letter' => { >+ 'content' => 'a message', >+ 'metadata' => 'metadata', >+ 'code' => 'TEST_MESSAGE', >+ 'content_type' => 'text/plain', >+ 'title' => 'message title' >+ }, >+ 'borrowernumber' => $borrowernumber, >+ 'to_address' => undef, >+ 'message_transport_type' => 'sms', >+ 'from_address' => 'from@example.com' >+ }; >+ my $my_message2 = { >+ 'letter' => { >+ 'content' => 'another message', >+ 'metadata' => 'metadata', >+ 'code' => 'TEST_MESSAGE', >+ 'content_type' => 'text/plain', >+ 'title' => 'message title' >+ }, >+ 'borrowernumber' => $borrowernumber, >+ 'to_address' => undef, >+ 'message_transport_type' => 'sms', >+ 'from_address' => 'from@example.com' >+ }; >+ my $my_message3 = { >+ 'letter' => { >+ 'content' => 'a skipped message', >+ 'metadata' => 'metadata', >+ 'code' => 'TEST_MESSAGE', >+ 'content_type' => 'text/plain', >+ 'title' => 'message title' >+ }, >+ 'borrowernumber' => $borrowernumber, >+ 'to_address' => undef, >+ 'message_transport_type' => 'sms', >+ 'from_address' => 'from@example.com' >+ }; >+ C4::Letters::EnqueueLetter($my_message); >+ C4::Letters::EnqueueLetter($my_message2); >+ C4::Letters::EnqueueLetter($my_message3); >+ my $messages_processed = C4::Letters::SendQueuedMessages( { content_not_like => 'skipped' } ); >+ is( $messages_processed, 2, "Correctly skipped processing one message containing the work 'skipped' in contents" ); >+}; >+ > subtest 'Test limit parameter for SendQueuedMessages' => sub { > plan tests => 3; > >-- >2.30.2
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 31453
:
139736
|
139828
|
142895
|
145756
|
147478