Skip to content

Commit

Permalink
swoole fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rez1dent3 committed Sep 29, 2022
1 parent fba5b68 commit 2b9a218
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"phpunit/phpunit": "^9.5",
"rector/rector": "^0.14",
"symplify/easy-coding-standard": "^11.1",
"vimeo/psalm": "^4.26"
"vimeo/psalm": "^4.27"
},
"suggest": {
"bavix/laravel-wallet-swap": "Addition to the laravel-wallet library for quick setting of exchange rates",
Expand Down
4 changes: 2 additions & 2 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ parameters:

-
message: "#^Method Bavix\\\\Wallet\\\\Internal\\\\Service\\\\StateService\\:\\:get\\(\\) should return string\\|null but returns mixed\\.$#"
count: 1
count: 2
path: src/Internal/Service/StateService.php

-
message: "#^Trying to invoke mixed but it's not a callable\\.$#"
message: "#^Parameter \\#2 \\$callback of method Illuminate\\\\Contracts\\\\Cache\\\\Repository\\:\\:rememberForever\\(\\) expects Closure, mixed given\\.$#"
count: 1
path: src/Internal/Service/StateService.php

Expand Down
29 changes: 15 additions & 14 deletions src/Internal/Service/DatabaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,41 +41,42 @@ public function transaction(callable $callback): mixed
);
}

if ($level > 0) {
return $callback();
}

$this->init = true;

try {
if ($level > 0) {
return $callback();
}

$this->regulatorService->purge();

return $this->connection->transaction(function () use ($callback) {
$result = $callback();
$this->init = false;

if ($result === false || (is_countable($result) && count($result) === 0)) {
$this->regulatorService->purge();
} else {
$this->regulatorService->approve();
if ($result === false) {
return false;
}

if (is_countable($result) && count($result) === 0) {
return $result;
}

$this->regulatorService->approve();

return $result;
});
} catch (RecordsNotFoundException|ExceptionInterface $exception) {
$this->regulatorService->purge();
$this->init = false;

throw $exception;
} catch (Throwable $throwable) {
$this->regulatorService->purge();
$this->init = false;

throw new TransactionFailedException(
'Transaction failed. Message: ' . $throwable->getMessage(),
ExceptionInterface::TRANSACTION_FAILED,
$throwable
);
} finally {
$this->regulatorService->purge();
$this->init = false;
}
}
}
10 changes: 6 additions & 4 deletions src/Internal/Service/StateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,24 @@ public function __construct(CacheFactory $cacheFactory)

public function fork(string $uuid, callable $value): void
{
$this->forkCallables->add(self::PREFIX_FORK_CALL . $uuid, $value);
if (! $this->forks->has(self::PREFIX_FORKS . $uuid)) {
$this->forkCallables->put(self::PREFIX_FORK_CALL . $uuid, $value);
}
}

public function get(string $uuid): ?string
{
$callable = $this->forkCallables->pull(self::PREFIX_FORK_CALL . $uuid);
if ($callable !== null) {
$this->forks->put(self::PREFIX_FORKS . $uuid, (string) $callable());
return $this->forks->rememberForever(self::PREFIX_FORKS . $uuid, $callable);
}

return $this->forks->get(self::PREFIX_FORKS . $uuid);
}

public function drop(string $uuid): void
{
$this->forkCallables->delete(self::PREFIX_FORK_CALL . $uuid);
$this->forks->delete(self::PREFIX_FORKS . $uuid);
$this->forkCallables->forget(self::PREFIX_FORK_CALL . $uuid);
$this->forks->forget(self::PREFIX_FORKS . $uuid);
}
}
2 changes: 1 addition & 1 deletion src/Internal/Service/StorageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

final class StorageService implements StorageServiceInterface
{
private const PREFIX = 'wallet_strg::';
private const PREFIX = 'wallet_sg::';

public function __construct(
private MathServiceInterface $mathService,
Expand Down
2 changes: 1 addition & 1 deletion src/Services/RegulatorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ public function approve(): void
$event = $this->balanceUpdatedEventAssembler->create($wallet);
$this->dispatcherService->dispatch($event);
}
} finally {
$this->dispatcherService->flush();
} finally {
$this->purge();
}
}
Expand Down

0 comments on commit 2b9a218

Please sign in to comment.