forked from tradecoverexchange/google-cloud-tasks-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCloudQueueModifier.php
33 lines (28 loc) · 1001 Bytes
/
CloudQueueModifier.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
namespace TradeCoverExchange\GoogleCloudTaskLaravel;
use Google\Cloud\Tasks\V2beta3\Queue as CloudQueue;
use Google\Cloud\Tasks\V2beta3\RateLimits;
use Google\Cloud\Tasks\V2beta3\RetryConfig;
use Google\Protobuf\Duration;
class CloudQueueModifier
{
public function apply(CloudQueue $queue, array $config): CloudQueue
{
if ($config['rate_limits'] ?? false) {
$queue->setRateLimits(new RateLimits($config['rate_limits']));
}
if ($config['retry_config'] ?? false) {
$queue->setRetryConfig(new RetryConfig(
collect($config['retry_config'])
->map(function ($value, $key) {
if (in_array($key, ['max_backoff', 'min_backoff', 'max_retry_duration'])) {
return new Duration($value);
}
return $value;
})
->all()
));
}
return $queue;
}
}