1
0
Fork 0
mirror of synced 2025-04-12 13:30:55 +00:00

Compare commits

...

2 commits

Author SHA1 Message Date
Alex Lushpai
a06ec22341
Merge pull request #9 from curse89/modify-middleware
add-ttl-for-middleware
2023-10-18 14:28:42 +03:00
Сергей Кривич
f15d9a2a86 add-ttl-for-middleware 2023-10-18 14:15:32 +03:00

View file

@ -21,9 +21,15 @@ class LockableMessageMiddleware implements MiddlewareInterface
*/ */
private $lockFactory; private $lockFactory;
public function __construct(LockFactory $lockFactory) /**
* @var int|null
*/
private $ttl;
public function __construct(LockFactory $lockFactory, int $ttl = null)
{ {
$this->lockFactory = $lockFactory; $this->lockFactory = $lockFactory;
$this->ttl = $ttl;
} }
/** /**
@ -39,7 +45,7 @@ class LockableMessageMiddleware implements MiddlewareInterface
$message = $envelope->getMessage(); $message = $envelope->getMessage();
if ($envelope->all(ReceivedStamp::class) && $message instanceof LockableMessage) { 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()) { if (!$lock->acquire()) {
return $envelope; return $envelope;
} }