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 Dec 12, 2023
1 parent 9f9207e commit 213d14b
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
Expand Up @@ -5,6 +5,7 @@
- 2023-11-30 Added missing links to widget on CustomerUserInformationCenter: create phone ticket, create email ticket, switch to customer.
- 2023-11-17 Increased size of text columns for standard templates and notification event messages. Thanks for reporting to @BurtGummer. [#504](https://github.com/znuny/Znuny/issues/504)
- 2023-11-17 Pending dashboards now show all pending tickets.
- 2023-11-13 Added option 'send-timeout' to console command Maint::Email::MailQueue.
- 2023-11-10 Sessions will now be removed immediately (instead of by daemon task) if a user will be renamed, leading to a direct logout if a user renames himself.
- 2023-11-06 Sector Nord AG: Fixed encoding of shown changes on subaction ViewDiff of AdminPackageManager. Thanks to Ziggy Trotter (@ZTrotter), Sector Nord AG. [PR#486](https://github.com/znuny/Znuny/pull/486)
- 2023-11-06 Sector Nord AG: Fixed CTRL+left click in ticket overviews. Thanks to Ziggy Trotter (@ZTrotter), Sector Nord AG. [PR#487](https://github.com/znuny/Znuny/pull/487)
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 213d14b

Please sign in to comment.