add-ttl-for-middleware
This commit is contained in:
parent
a104eebf2a
commit
f15d9a2a86
@ -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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user