mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
fix: lock domain purchase if already launched
This commit is contained in:
@@ -17,8 +17,11 @@ use App\Service\Provider\AbstractProvider;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Target;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Symfony\Component\Lock\Key;
|
||||
use Symfony\Component\Lock\LockFactory;
|
||||
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
|
||||
use Symfony\Component\Mailer\MailerInterface;
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
@@ -43,7 +46,10 @@ final readonly class OrderDomainHandler
|
||||
#[Autowire(service: 'service_container')]
|
||||
private ContainerInterface $locator,
|
||||
#[Autowire(param: 'influxdb_enabled')]
|
||||
private bool $influxdbEnabled, private EntityManagerInterface $em, private DomainPurchaseRepository $domainPurchaseRepository,
|
||||
private bool $influxdbEnabled, private EntityManagerInterface $em,
|
||||
private DomainPurchaseRepository $domainPurchaseRepository,
|
||||
#[Target('lock')]
|
||||
private LockFactory $lockFactory,
|
||||
) {
|
||||
$this->sender = new Address($mailerSenderEmail, $mailerSenderName);
|
||||
}
|
||||
@@ -72,6 +78,23 @@ final readonly class OrderDomainHandler
|
||||
return;
|
||||
}
|
||||
|
||||
$lock = $this->lockFactory->createLockFromKey(
|
||||
new Key('domain_purchase.'.$domain->getLdhName().'.'.$connector->getId()),
|
||||
ttl: 600,
|
||||
autoRelease: false
|
||||
);
|
||||
|
||||
if (!$lock->acquire()) {
|
||||
$this->logger->notice('Purchase attempt is already launched for this domain name with this connector', [
|
||||
'watchlist' => $message->watchlistToken,
|
||||
'connector' => $connector->getId(),
|
||||
'ldhName' => $message->ldhName,
|
||||
'provider' => $connector->getProvider()->value,
|
||||
]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->logger->notice('Watchlist is linked to a connector : a purchase attempt will be made for this domain name', [
|
||||
'watchlist' => $message->watchlistToken,
|
||||
'connector' => $connector->getId(),
|
||||
@@ -162,6 +185,8 @@ final readonly class OrderDomainHandler
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
$lock->release();
|
||||
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class DomainPurchaseRepository extends ServiceEntityRepository
|
||||
{
|
||||
return $this->createQueryBuilder('dp')
|
||||
->select('COUNT(dp)')
|
||||
->where('dp.domainOrderedAt not NULL')
|
||||
->where('dp.domainOrderedAt IS NOT NULL')
|
||||
->getQuery()->getSingleScalarResult();
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class DomainPurchaseRepository extends ServiceEntityRepository
|
||||
{
|
||||
return $this->createQueryBuilder('dp')
|
||||
->select('COUNT(dp)')
|
||||
->where('dp.domainOrderedAt is NULL')
|
||||
->where('dp.domainOrderedAt IS NULL')
|
||||
->getQuery()->getSingleScalarResult();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user