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()); } /**