Skip to content

Commit

Permalink
Add debug mode to retry service
Browse files Browse the repository at this point in the history
  • Loading branch information
RikudouSage committed Aug 27, 2024
1 parent c593663 commit 97d2516
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
parameters:
default_aws_region: us-east-1
aws_region: '%env(default:default_aws_region:AWS_REGION)%'
debug_mode: '%env(bool:GOG_DOWNLOADER_DEBUG)%'

services:
_defaults:
Expand Down Expand Up @@ -45,3 +46,7 @@ services:
arguments:
- version: latest
region: '%aws_region%'

App\Service\RetryService:
arguments:
$debug: '%debug_mode%'
10 changes: 9 additions & 1 deletion src/Service/RetryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
use App\Exception\TooManyRetriesException;
use Throwable;

final class RetryService
final readonly class RetryService
{
public function __construct(
private bool $debug,
) {
}

/**
* @throws TooManyRetriesException
* @throws Throwable
Expand All @@ -20,6 +25,9 @@ public function retry(callable $callable, int $maxRetries, int $retryDelay, ?arr

return;
} catch (Throwable $e) {
if ($this->debug) {
throw $e;
}
++$retries;
if (!$this->matches($e, $exceptions)) {
throw $e;
Expand Down

0 comments on commit 97d2516

Please sign in to comment.