-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #399 from UN-OCHA/cafuego/ops-9523-ses-updates
chore: Replace the amazon_ses patch link with a set that actually applies to 3.0.1 instead of 3.0.x-dev only.
- Loading branch information
Showing
4 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
diff --git a/src/AmazonSesHandler.php b/src/AmazonSesHandler.php | ||
index 28342d8..103829c 100644 | ||
--- a/src/AmazonSesHandler.php | ||
+++ b/src/AmazonSesHandler.php | ||
@@ -126,6 +126,12 @@ class AmazonSesHandler implements AmazonSesHandlerInterface { | ||
*/ | ||
protected function getSleepTime() { | ||
$results = $this->getSendQuota(); | ||
+ | ||
+ // Avoid a division by zero if the quota call failed. | ||
+ if (empty($results)) { | ||
+ return 0; | ||
+ } | ||
+ | ||
$per_second = ceil(1000000 / $results['MaxSendRate']); | ||
|
||
return intval($per_second); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
diff --git a/src/Plugin/QueueWorker/AmazonSesMailQueue.php b/src/Plugin/QueueWorker/AmazonSesMailQueue.php | ||
index dc41050..fdc7af3 100644 | ||
--- a/src/Plugin/QueueWorker/AmazonSesMailQueue.php | ||
+++ b/src/Plugin/QueueWorker/AmazonSesMailQueue.php | ||
@@ -29,7 +29,12 @@ class AmazonSesMailQueue extends QueueWorkerBase implements ContainerFactoryPlug | ||
$plugin_definition | ||
); | ||
|
||
- $instance->setHandler($container->get('amazon_ses.handler')); | ||
+ // Only set the handler if queueing is enabled to avoid an error when | ||
+ // trying to run without config. | ||
+ $enabled = \Drupal::config('amazon_ses.settings')->get('queue'); | ||
+ if ($enabled) { | ||
+ $instance->setHandler($container->get('amazon_ses.handler')); | ||
+ } | ||
|
||
return $instance; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
diff --git a/src/AmazonSesHandler.php b/src/AmazonSesHandler.php | ||
index ed8882c..cb2fb01 100644 | ||
--- a/src/AmazonSesHandler.php | ||
+++ b/src/AmazonSesHandler.php | ||
@@ -194,9 +194,16 @@ class AmazonSesHandler implements AmazonSesHandlerInterface { | ||
* {@inheritdoc} | ||
*/ | ||
public function getSendQuota() { | ||
- $result = $this->client->getAccount(); | ||
+ $quota = []; | ||
|
||
- return array_map('number_format', $result['SendQuota']); | ||
+ try { | ||
+ $result = $this->client->getAccount(); | ||
+ $quota = array_map('number_format', $result['SendQuota']); | ||
+ } catch (SesV2Exception $e) { | ||
+ $this->logger->error($e->getMessage()); | ||
+ $this->messenger->addError($this->t('Unable to retrieve quota.')); | ||
+ } | ||
+ return $quota; | ||
} | ||
|
||
/** | ||
diff --git a/src/Controller/AmazonSesController.php b/src/Controller/AmazonSesController.php | ||
index 541838c..831d38d 100644 | ||
--- a/src/Controller/AmazonSesController.php | ||
+++ b/src/Controller/AmazonSesController.php | ||
@@ -29,33 +29,38 @@ class AmazonSesController extends ControllerBase { | ||
* A render array to build the page. | ||
*/ | ||
public function statistics() { | ||
+ $statistics = []; | ||
+ | ||
if (!$this->verifyClient()) { | ||
- return []; | ||
+ return $statistics; | ||
} | ||
|
||
- $quota = $this->handler->getSendQuota(); | ||
- | ||
- return [ | ||
- 'quota' => [ | ||
- '#type' => 'details', | ||
- '#title' => $this->t('Daily sending limits'), | ||
- '#open' => TRUE, | ||
- 'sending_quota' => [ | ||
- '#markup' => $this->t('<strong>Quota:</strong> @max_send', [ | ||
- '@max_send' => $quota['Max24HourSend'], | ||
- ]) . '<br />', | ||
- ], | ||
- 'sent_mail' => [ | ||
- '#markup' => $this->t('<strong>Sent:</strong> @sent_last', [ | ||
- '@sent_last' => $quota['SentLast24Hours'], | ||
- ]) . '<br />', | ||
- ], | ||
- 'send_rate' => [ | ||
- '#markup' => $this->t('<strong>Maximum Send Rate:</strong> @send_rate | ||
- emails/second', ['@send_rate' => $quota['MaxSendRate']]), | ||
+ $result = $this->handler->getSendQuota(); | ||
+ | ||
+ if (!empty($result)) { | ||
+ $statistics = [ | ||
+ 'quota' => [ | ||
+ '#type' => 'details', | ||
+ '#title' => $this->t('Daily sending limits'), | ||
+ '#open' => TRUE, | ||
+ 'sending_quota' => [ | ||
+ '#markup' => $this->t('<strong>Quota:</strong> @max_send', [ | ||
+ '@max_send' => $result['Max24HourSend'], | ||
+ ]) . '<br />', | ||
+ ], | ||
+ 'sent_mail' => [ | ||
+ '#markup' => $this->t('<strong>Sent:</strong> @sent_last', [ | ||
+ '@sent_last' => $result['SentLast24Hours'], | ||
+ ]) . '<br />', | ||
+ ], | ||
+ 'send_rate' => [ | ||
+ '#markup' => $this->t('<strong>Maximum Send Rate:</strong> @send_rate | ||
+ emails/second', ['@send_rate' => $result['MaxSendRate']]), | ||
+ ], | ||
], | ||
- ], | ||
- ]; | ||
- } | ||
+ ]; | ||
+ } | ||
|
||
+ return $statistics; | ||
+ } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters