Skip to content

Fixed bug, when function Retry::backoffType always return SlowBackoff #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
* fixed bug, when function Retry::backoffType always return SlowBackoff

# 1.8.0

* update destructor in MemorySessionPool
* fixed exception on re-create server nodes
* fixed key name in createTable function
Expand Down
4 changes: 2 additions & 2 deletions src/Retry/Retry.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function retry(Closure $closure, bool $idempotent)
$retryCount = 0;
$lastException = null;
while (microtime(true) < $startTime + $this->timeoutMs / 1000) {
$this->logger->debug("YDB: Run user function. Retry count: $retryCount. Ms: ".(microtime(true) - $startTime));
$this->logger->debug("YDB: Run user function. Retry count: $retryCount. s: ".(microtime(true) - $startTime));
try {
return $closure();
} catch (Exception $e) {
Expand All @@ -89,7 +89,7 @@ public function retry(Closure $closure, bool $idempotent)
}
$retryCount++;
$lastException = $e;
$delay = $this->retryDelay($retryCount, $this->backoffType($e))*1000;
$delay = $this->retryDelay($retryCount, $this->backoffType(get_class($e)))*1000;
usleep($delay);
}
}
Expand Down
6 changes: 4 additions & 2 deletions tests/RetryOnExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use YdbPlatform\Ydb\Session;
use YdbPlatform\Ydb\Table;
use YdbPlatform\Ydb\Ydb;
use YdbPlatform\Ydb\Logger\SimpleFileLogger;

class SessionManager extends \YdbPlatform\Ydb\Session{
public static function setSessionId(\YdbPlatform\Ydb\Session $session, string $id){
Expand Down Expand Up @@ -46,7 +47,8 @@ public function test(){
'credentials' => new AnonymousAuthentication()
];

$ydb = new Ydb($config);
$ydb = new Ydb($config, new SimpleFileLogger(7, "l.log"));
// $ydb = new Ydb($config);
$table = $ydb->table();

$session = $table->createSession();
Expand All @@ -69,6 +71,6 @@ private function retryTest(Table $table)
1,
$tres
);
}, true, new RetryParams(20000));
}, true, new RetryParams(2000));
}
}