1
0
mirror of synced 2024-11-21 20:36:08 +03:00

Merge pull request #9 from curse89/modify-middleware

add-ttl-for-middleware
This commit is contained in:
Alex Lushpai 2023-10-18 14:28:42 +03:00 committed by GitHub
commit a06ec22341
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;
}