From d61d71461fb1a7c963e3ccccd149bbf7940db8d6 Mon Sep 17 00:00:00 2001 From: Jens Pfeifer Date: Tue, 21 Nov 2023 07:27:11 +0000 Subject: [PATCH] Added option 'send-timeout' to console command Maint::Email::MailQueue. --- CHANGES.md | 1 + .../Console/Command/Maint/Email/MailQueue.pm | 31 ++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index c49976082b9..d382ec77838 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,6 @@ # 7.0.14 2023-??-?? - 2023-11-17 Pending dashboards now show all pending tickets. + - 2023-11-13 Added option 'send-timeout' to console command Maint::Email::MailQueue. # 7.0.13 2023-11-15 - 2023-11-09 Added missing links to widget on CustomerUserInformationCenter: create phone ticket, create email ticket, switch to customer. diff --git a/Kernel/System/Console/Command/Maint/Email/MailQueue.pm b/Kernel/System/Console/Command/Maint/Email/MailQueue.pm index 425360dd35e..89e095244be 100644 --- a/Kernel/System/Console/Command/Maint/Email/MailQueue.pm +++ b/Kernel/System/Console/Command/Maint/Email/MailQueue.pm @@ -31,6 +31,14 @@ sub Configure { Required => 0, HasValue => 0, ); + $Self->AddOption( + Name => 'send-timeout', + Description => + "Timeout in seconds to kill the process that sends emails (default: 600).", + Required => 0, + HasValue => 1, + ValueRegex => qr{^\d+$}smx, + ); $Self->AddOption( Name => 'list', Description => "List available messages in the mail queue (can be used with --filter).", @@ -191,14 +199,29 @@ sub Send { my $SendCounter = 0; my $ForceSending = $Self->GetOption('force'); my $Verbose = $Self->GetOption('verbose'); + my $SendTimeout = $Self->GetOption('send-timeout') // 600; MAILQUEUE: for my $Item (@$List) { + my $Result; - my $Result = $MailQueueObject->Send( - %{$Item}, - Force => $ForceSending, - ); + eval { + + # Set up alarm signal handler to kill the running process if given timeout will be reached. + local $SIG{ALRM} = sub { die; }; + alarm $SendTimeout; + + $Result = $MailQueueObject->Send( + %{$Item}, + Force => $ForceSending, + ); + }; + + if ($@) { + my $ErrorMessage = "Timeout of $SendTimeout seconds reached, killing process.\n"; + $Self->PrintError($ErrorMessage); + die $ErrorMessage; + } if ( $Result->{Status} eq 'Pending' ) { $Self->Print("\nPending message with ID '$Item->{ID}' was not sent.\n");