You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I am using CommandPool for SES (AWS PHP SDK 3.173).
I am using MockHandler to test and have it generate an AwsException randomly.
If I have 15 emails in the pool, and if one of them throws an exception, the entire CommandPool stops (the aggregate gets rejected).
What I was looking for, was a way to continue execution of all commands in the pool even if a few received the exception.
Please let me know if there is a way to do this.
Thanks
Command Pool:
$commandGenerator = function ($emailsReady) use ($sesClient) {
foreach ($emailsReady as $message) {
// Yield a command that is executed by the pool
yield $sesClient->getCommand(
'sendEmail',
$message['details']
);
}
};
// Now create the generator using the emails iterator
$sendEmailCommands = $commandGenerator($emailsReady);
$pool = new CommandPool($sesClient, $sendEmailCommands, [
'concurrency' => 15,
'preserve_iterator_keys' => true, // (bool) Retain the iterator key when generating the commands
// Invoke this function before executing each command
'before' => function (CommandInterface $cmd, $iterKey) use ($emailsReady, &$cnt) {
echo "About to send {$iterKey}: " . "\n";
},
// Invoke this function for each successful transfer
'fulfilled' => function (
ResultInterface $result,
$iterKey,
PromiseInterface $aggregatePromise
) use ($emailsReady) {
echo "Completed {$iterKey}: {$result}\n";
},
// Invoke this function for each failed transfer
'rejected' => function (
AwsException $reason,
$iterKey,
PromiseInterface $aggregatePromise
) use ($emailsReady) {
echo $reason->getMessage() . PHP_EOL;
echo "Failed {$iterKey}: {$reason}\n";
},
]);
// Initiate the pool transfers
$pool->promise();
Mock Handler:
$mock = new MockHandler();
$mock->append(function (CommandInterface $cmd, RequestInterface $request) {
$result = new Result(['foo' => 'bar']);
if (mt_rand(1, 10) <= 5) {
return Create::promiseFor($result);
} else {
return new AwsException('Mock exception', $cmd);
}
});
Output
About to send 0:
About to send 1:
About to send 2:
About to send 3:
About to send 4:
About to send 5:
About to send 6:
About to send 7:
About to send 8:
About to send 9:
About to send 10:
About to send 11:
About to send 12:
About to send 13:
About to send 14:
Completed 0: Model Data
----------
Data can be retrieved from the model object using the get() method of the
model (e.g., `$result->get($key)`) or "accessing the result like an
associative array (e.g. `$result['key']`). You can also execute JMESPath
expressions on the result data using the search() method.
{
"foo": "bar",
"@metadata": {
"effectiveUri": "https:\/\/email.us-east-1.amazonaws.com",
"statusCode": 200,
"transferStats": {
"http": [
[]
],
"total_time": 0.08518815040588379
}
}
}
Mock exception
Failed 1: Aws\Exception\AwsException: Mock exception in /var/www/html/app/Modules/Accounts/Models/Account.php:218
Stack trace:
#0 /var/www/html/vendor/aws/aws-sdk-php/src/MockHandler.php(94):
#1 /var/www/html/vendor/aws/aws-sdk-php/src/ClientSideMonitoring/AbstractMonitoringMiddleware.php(126): Aws\MockHandler->__invoke()
#2 /var/www/html/vendor/aws/aws-sdk-php/src/Middleware.php(126): Aws\ClientSideMonitoring\AbstractMonitoringMiddleware->__invoke()
#3 /var/www/html/vendor/guzzlehttp/promises/src/FulfilledPromise.php(41): Aws\Middleware::Aws\{closure}()
#4 /var/www/html/vendor/guzzlehttp/promises/src/TaskQueue.php(48): GuzzleHttp\Promise\FulfilledPromise::GuzzleHttp\Promise\{closure}()
#5 /var/www/html/vendor/guzzlehttp/promises/src/TaskQueue.php(27): GuzzleHttp\Promise\TaskQueue->run()
#6 [internal function]: GuzzleHttp\Promise\TaskQueue->GuzzleHttp\Promise\{closure}()
#7 {main}
What I would like is to have the remaining ones processed above. The CommandPool stopped execution on the second item as soon as it hit an exception.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi,
I am using CommandPool for SES (AWS PHP SDK 3.173).
I am using MockHandler to test and have it generate an AwsException randomly.
If I have 15 emails in the pool, and if one of them throws an exception, the entire CommandPool stops (the aggregate gets rejected).
What I was looking for, was a way to continue execution of all commands in the pool even if a few received the exception.
Please let me know if there is a way to do this.
Thanks
Command Pool:
Mock Handler:
Output
What I would like is to have the remaining ones processed above. The CommandPool stopped execution on the second item as soon as it hit an exception.
Beta Was this translation helpful? Give feedback.
All reactions