Skip to content

Commit

Permalink
Merge pull request #15 from CPS-IT/feature/threshold
Browse files Browse the repository at this point in the history
[FEATURE] Allow configuration of queue delay threshold
  • Loading branch information
eliashaeussler authored Mar 7, 2024
2 parents 21036c2 + 63b9bc5 commit 6f2a1e2
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 9 deletions.
22 changes: 22 additions & 0 deletions Classes/Configuration/ExtensionConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,34 @@
*/
final class ExtensionConfiguration
{
private const DEFAULT_DELAY_THRESHOLD = 1800;
private const DEFAULT_ITEMS_PER_PAGE = 20;

public function __construct(
private readonly Core\Configuration\ExtensionConfiguration $configuration,
) {}

/**
* @return positive-int
*/
public function getQueueDelayThreshold(): int
{
try {
$delayThreshold = $this->configuration->get(Extension::KEY, 'queue/delayThreshold');
} catch (Core\Exception) {
return self::DEFAULT_DELAY_THRESHOLD;
}

if (!is_scalar($delayThreshold)) {
return self::DEFAULT_DELAY_THRESHOLD;
}

return max(1, (int)$delayThreshold);
}

/**
* @return positive-int
*/
public function getItemsPerPage(): int
{
try {
Expand Down
2 changes: 2 additions & 0 deletions Classes/Controller/MailqueueModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public function __invoke(Message\ServerRequestInterface $request): Message\Respo

/**
* @return array{
* delayThreshold: positive-int,
* failing: bool,
* longestPendingInterval: non-negative-int,
* pagination: Core\Pagination\SimplePagination,
Expand Down Expand Up @@ -140,6 +141,7 @@ private function resolveTemplateVariables(
$pagination = new Core\Pagination\SimplePagination($paginator);

return [
'delayThreshold' => $this->extensionConfiguration->getQueueDelayThreshold(),
'failing' => $failing,
'longestPendingInterval' => $longestPendingInterval,
'pagination' => $pagination,
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,10 @@ $GLOBALS['TYPO3_CONF_VARS']['MAIL']['transport_spool_type'] = \Vendor\Extension\

The following extension configuration options are available:

| Configuration key | Description | Required | Default |
|-------------------------------|----------------------------------------------------------------|----------|---------|
| **`pagination.itemsPerPage`** | Number of mails to display on a single page in backend module || `20` |
| Configuration key | Description | Required | Default |
|-------------------------------|---------------------------------------------------------------------------|----------|---------|
| **`queue.delayThreshold`** | Number in seconds after which a mail in the queue is considered "delayed" || `1800` |
| **`pagination.itemsPerPage`** | Number of mails to display on a single page in backend module || `20` |

## 🧑‍💻 Contributing

Expand Down
2 changes: 1 addition & 1 deletion Resources/Private/Language/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<source>At least one mail could not be sent. You may check your mail transport and verify if everything works as intended.</source>
</trans-unit>
<trans-unit id="alert.stuckTransport.message">
<source>It seems like some mails were not sent for at least 30 minutes. Make sure to periodically flush the mail queue.</source>
<source>It seems like some mails have been in the queue for some time. Make sure to periodically flush the mail queue.</source>
</trans-unit>
<trans-unit id="alert.noIssues.message">
<source>The mail queue seems to be healthy. Make sure to periodically flush it.</source>
Expand Down
4 changes: 2 additions & 2 deletions Resources/Private/Partials/List/Queue.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ <h2>{f:translate(key: 'header.status', extensionName: 'Mailqueue')}</h2>
message="{f:translate(key: 'alert.failedTransports.message', extensionName: 'Mailqueue')}"
/>
</f:if>
<f:if condition="{longestPendingInterval} > 1800">
<f:if condition="{longestPendingInterval} > {delayThreshold}">
<f:be.infobox state="1"
message="{f:translate(key: 'alert.stuckTransport.message', extensionName: 'Mailqueue')}"
/>
</f:if>
<f:if condition="!{failing} && {longestPendingInterval} < 1800">
<f:if condition="!{failing} && {longestPendingInterval} < {delayThreshold}">
<f:be.infobox state="0"
message="{f:translate(key: 'alert.noIssues.message', extensionName: 'Mailqueue')}"
/>
Expand Down
6 changes: 3 additions & 3 deletions Resources/Private/Partials/List/QueueItem.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</f:if>
</f:case>
<f:case value="queued">
<f:if condition="{queueItem.date} && {queueItem.date -> m:dateInterval()} >= 1800">
<f:if condition="{queueItem.date} && {queueItem.date -> m:dateInterval()} >= {delayThreshold}">
<f:then>
<span class="badge badge-warning d-block">{f:translate(key: 'queueItem.state.late', extensionName: 'Mailqueue')}</span>
</f:then>
Expand All @@ -24,7 +24,7 @@
</f:if>
</f:case>
<f:case value="sending">
<f:if condition="{queueItem.date} && {queueItem.date -> m:dateInterval()} >= 1800">
<f:if condition="{queueItem.date} && {queueItem.date -> m:dateInterval()} >= {delayThreshold}">
<f:then>
<span class="badge badge-warning d-block">{f:translate(key: 'queueItem.state.late', extensionName: 'Mailqueue')}</span>
</f:then>
Expand Down Expand Up @@ -86,7 +86,7 @@

<f:section name="rowClass">
<f:switch expression="{state.value}">
<f:case value="queued"><f:if condition="{date} && {date -> m:dateInterval()} >= 1800">warning</f:if></f:case>
<f:case value="queued"><f:if condition="{date} && {date -> m:dateInterval()} >= {delayThreshold}">warning</f:if></f:case>
<f:case value="failed">danger</f:case>
<f:case value="sending">warning</f:case>
</f:switch>
Expand Down
1 change: 1 addition & 0 deletions Resources/Private/Templates/List.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ <h1>{f:translate(key: 'header.list', extensionName: 'Mailqueue')}</h1>
</f:then>
<f:else>
<f:render partial="List/Queue" arguments="{
delayThreshold: delayThreshold,
failing: failing,
longestPendingInterval: longestPendingInterval,
pagination: pagination,
Expand Down
3 changes: 3 additions & 0 deletions ext_conf_template.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# cat=queue//10; type=int+; label=Number in seconds after which a mail in the queue is considered "delayed"
queue.delayThreshold = 1800

# cat=pagination//10; type=int+; label=Number of mails to display on a single page in backend module list pagination
pagination.itemsPerPage = 20

0 comments on commit 6f2a1e2

Please sign in to comment.