Skip to content

Commit

Permalink
Added logging to PutCuratorReviewExceptionHandler.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilge committed Nov 15, 2023
1 parent 1846ee6 commit 33ff9bf
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
22 changes: 20 additions & 2 deletions src/Import/PutCuratorReviewExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace ScriptFUSION\Steam250\Curator\Import;

use Psr\Log\LoggerInterface;
use ScriptFUSION\Porter\Connector\Recoverable\ExponentialAsyncDelayRecoverableExceptionHandler;
use ScriptFUSION\Porter\Connector\Recoverable\RecoverableException;
use ScriptFUSION\Porter\Connector\Recoverable\RecoverableExceptionHandler;
Expand All @@ -13,17 +14,27 @@ final class PutCuratorReviewExceptionHandler implements RecoverableExceptionHand
{
private RecoverableExceptionHandler $exceptionHandler;

private LoggerInterface $logger;

public function __construct(private int $appId)
{
}

public function initialize(): void
{
$this->exceptionHandler = new ExponentialAsyncDelayRecoverableExceptionHandler(
// Wait at least a minute before trying again.
600 * AsyncExponentialBackoffExceptionHandler::DEFAULT_COEFFICIENT
// Wait at least 10 seconds before trying again.
100 * AsyncExponentialBackoffExceptionHandler::DEFAULT_COEFFICIENT
);
$this->exceptionHandler->initialize();
}

public function __invoke(RecoverableException $exception): void
{
$this->logger && $this->logger->info(
"Retrying #$this->appId: " . get_debug_type($exception) . ": {$exception->getMessage()}"
);

if ($exception instanceof HttpServerException && $exception->getCode() === 400) {
$response = \json_decode($exception->getResponse()->getBody());
if ($response->success === 8) {
Expand All @@ -33,4 +44,11 @@ public function __invoke(RecoverableException $exception): void

($this->exceptionHandler)($exception);
}

public function setLogger(LoggerInterface $logger): self
{
$this->logger = $logger;

return $this;
}
}
14 changes: 13 additions & 1 deletion src/Import/PutCuratorReviewImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

namespace ScriptFUSION\Steam250\Curator\Import;

use Psr\Log\LoggerInterface;
use ScriptFUSION\Porter\Connector\Recoverable\RecoverableExceptionHandler;
use ScriptFUSION\Porter\Import\Import;
use ScriptFUSION\Porter\Provider\Steam\Resource\Curator\CuratorReview;
use ScriptFUSION\Porter\Provider\Steam\Resource\Curator\CuratorSession;
Expand All @@ -14,6 +16,7 @@ final class PutCuratorReviewImport extends Import
{
private const LANG = 'en';

private RecoverableExceptionHandler $exceptionHandler;

public function __construct(CuratorSession $session, int $curatorId, array $app)
{
Expand Down Expand Up @@ -41,6 +44,15 @@ public function __construct(CuratorSession $session, int $curatorId, array $app)
))->setUrl("https://steam250.com{$ranking->getUrlPath()}#app/$app[app_id]/" . rawurlencode($app['name']))
));

$this->setRecoverableExceptionHandler(new PutCuratorReviewExceptionHandler);
$this->setRecoverableExceptionHandler(
$this->exceptionHandler = new PutCuratorReviewExceptionHandler($app['app_id'])
);
}

public function setLogger(LoggerInterface $logger): self
{
$this->exceptionHandler->setLogger($logger);

return $this;
}
}
3 changes: 2 additions & 1 deletion src/ReviewSynchronizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ function () use ($app): array {
try {
return [
$this->porter->importOne(
new PutCuratorReviewImport($this->session, $this->curatorId, $app)
(new PutCuratorReviewImport($this->session, $this->curatorId, $app))
->setLogger($this->logger)
),
$app,
];
Expand Down

0 comments on commit 33ff9bf

Please sign in to comment.