From f15d9a2a86a8409b6af32cf55852a0af43d06bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9A=D1=80=D0=B8?= =?UTF-8?q?=D0=B2=D0=B8=D1=87?= Date: Wed, 18 Oct 2023 14:15:32 +0300 Subject: [PATCH] add-ttl-for-middleware --- Messenger/Middleware/LockableMessageMiddleware.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Messenger/Middleware/LockableMessageMiddleware.php b/Messenger/Middleware/LockableMessageMiddleware.php index 0718567..e01b372 100644 --- a/Messenger/Middleware/LockableMessageMiddleware.php +++ b/Messenger/Middleware/LockableMessageMiddleware.php @@ -21,9 +21,15 @@ class LockableMessageMiddleware implements MiddlewareInterface */ private $lockFactory; - public function __construct(LockFactory $lockFactory) + /** + * @var int|null + */ + private $ttl; + + public function __construct(LockFactory $lockFactory, int $ttl = null) { $this->lockFactory = $lockFactory; + $this->ttl = $ttl; } /** @@ -39,7 +45,7 @@ class LockableMessageMiddleware implements MiddlewareInterface $message = $envelope->getMessage(); if ($envelope->all(ReceivedStamp::class) && $message instanceof LockableMessage) { - $lock = $this->lockFactory->createLock($this->objectHash($message), null); + $lock = $this->lockFactory->createLock($this->objectHash($message), $this->ttl); if (!$lock->acquire()) { return $envelope; }