Skip to content

Commit

Permalink
Added option 'send-timeout' to console command Maint::Email::MailQueue.
Browse files Browse the repository at this point in the history
  • Loading branch information
jepf committed Nov 21, 2023
1 parent 332766b commit d61d714
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
31 changes: 27 additions & 4 deletions Kernel/System/Console/Command/Maint/Email/MailQueue.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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).",
Expand Down Expand Up @@ -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("\n<yellow>Pending message with ID '$Item->{ID}' was not sent.</yellow>\n");
Expand Down

0 comments on commit d61d714

Please sign in to comment.