From e35019b694d24136360bd8ba949ab2829b2f0564 Mon Sep 17 00:00:00 2001 From: Maksim Masukevich Date: Wed, 19 Aug 2020 17:32:17 +0200 Subject: [PATCH] Fix bug with obtain expired saga --- src/SagaStatus.php | 2 +- src/SagasProvider.php | 27 +++++++++++---------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/SagaStatus.php b/src/SagaStatus.php index 5b14f89..87d102a 100644 --- a/src/SagaStatus.php +++ b/src/SagaStatus.php @@ -47,7 +47,7 @@ final class SagaStatus */ public static function create(string $value): self { - if (false === \in_array($value, self::LIST, true)) + if (\in_array($value, self::LIST, true) === false) { throw InvalidSagaStatus::create($value); } diff --git a/src/SagasProvider.php b/src/SagasProvider.php index 56c89d0..fb37e6f 100644 --- a/src/SagasProvider.php +++ b/src/SagasProvider.php @@ -131,26 +131,19 @@ function () use ($id, $context): \Generator throw $throwable; } - try + if ($saga !== null) { - if ($saga !== null) + /** Non-expired saga */ + if ($saga->expireDate() > now()) { - /** Non-expired saga */ - if ($saga->expireDate() > now()) - { - return $saga; - } + return $saga; + } - yield from $this->doCloseExpired($saga, $context); + yield from $this->doCloseExpired($saga, $context); - throw new LoadedExpiredSaga( - \sprintf('Unable to load the saga (ID: "%s") whose lifetime has expired', $id->toString()) - ); - } - } - finally - { - yield from $this->releaseMutex($id); + throw new LoadedExpiredSaga( + \sprintf('Unable to load the saga (ID: "%s") whose lifetime has expired', $id->toString()) + ); } } ); @@ -266,6 +259,8 @@ private function doCloseExpired(Saga $saga, ServiceBusContext $context): \Genera yield $this->save($saga, $context); } + + yield from $this->releaseMutex($saga->id()); } /**