mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-17 17:55:42 +00:00
refactor: remove rate limiter and use retry strategy
This commit is contained in:
parent
4c1d0f731b
commit
6256ed8604
@ -14,8 +14,7 @@ framework:
|
|||||||
retry_strategy:
|
retry_strategy:
|
||||||
delay: 1000
|
delay: 1000
|
||||||
multiplier: 2
|
multiplier: 2
|
||||||
max_retries: 10
|
max_delay: 86400000
|
||||||
max_delay: 10000
|
|
||||||
|
|
||||||
failed: 'doctrine://default?queue_name=failed'
|
failed: 'doctrine://default?queue_name=failed'
|
||||||
# sync: 'sync://'
|
# sync: 'sync://'
|
||||||
@ -37,6 +36,3 @@ framework:
|
|||||||
App\Message\UpdateRdapServers: async
|
App\Message\UpdateRdapServers: async
|
||||||
App\Message\ValidateConnectorCredentials: async
|
App\Message\ValidateConnectorCredentials: async
|
||||||
App\Message\UpdateDomain: rdap_async
|
App\Message\UpdateDomain: rdap_async
|
||||||
|
|
||||||
# Route your messages to the transports
|
|
||||||
# 'App\Message\YourMessage': async
|
|
||||||
|
|||||||
@ -24,8 +24,3 @@ framework:
|
|||||||
policy: sliding_window
|
policy: sliding_window
|
||||||
limit: 10
|
limit: 10
|
||||||
interval: '1 hour'
|
interval: '1 hour'
|
||||||
|
|
||||||
rdap_requests:
|
|
||||||
policy: sliding_window
|
|
||||||
limit: 2
|
|
||||||
interval: '1 second'
|
|
||||||
|
|||||||
@ -79,8 +79,7 @@ final readonly class ProcessWatchlistHandler
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/** @var Domain $domain */
|
/** @var Domain $domain */
|
||||||
foreach ($watchlist->getDomains()->filter(fn ($domain) => $this->RDAPService->isToBeUpdated($domain, false, null !== $watchlist->getConnector())) as $domain
|
foreach ($watchlist->getDomains()->filter(fn ($domain) => $this->RDAPService->isToBeUpdated($domain, false, null !== $watchlist->getConnector())) as $domain) {
|
||||||
) {
|
|
||||||
$this->bus->dispatch(new UpdateDomain($domain->getLdhName(), $watchlist->getToken()));
|
$this->bus->dispatch(new UpdateDomain($domain->getLdhName(), $watchlist->getToken()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
namespace App\MessageHandler;
|
namespace App\MessageHandler;
|
||||||
|
|
||||||
use App\Entity\RdapServer;
|
use App\Entity\RdapServer;
|
||||||
|
use App\Entity\Watchlist;
|
||||||
use App\Exception\DomainNotFoundException;
|
use App\Exception\DomainNotFoundException;
|
||||||
use App\Exception\MalformedDomainException;
|
use App\Exception\MalformedDomainException;
|
||||||
use App\Exception\TldNotSupportedException;
|
use App\Exception\TldNotSupportedException;
|
||||||
@ -22,11 +23,9 @@ use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
|
|||||||
use Symfony\Component\Mailer\MailerInterface;
|
use Symfony\Component\Mailer\MailerInterface;
|
||||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||||
use Symfony\Component\Messenger\Exception\ExceptionInterface;
|
use Symfony\Component\Messenger\Exception\ExceptionInterface;
|
||||||
use Symfony\Component\Messenger\Exception\RecoverableMessageHandlingException;
|
|
||||||
use Symfony\Component\Messenger\MessageBusInterface;
|
use Symfony\Component\Messenger\MessageBusInterface;
|
||||||
use Symfony\Component\Mime\Address;
|
use Symfony\Component\Mime\Address;
|
||||||
use Symfony\Component\Notifier\Recipient\Recipient;
|
use Symfony\Component\Notifier\Recipient\Recipient;
|
||||||
use Symfony\Component\RateLimiter\RateLimiterFactory;
|
|
||||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||||
@ -46,7 +45,7 @@ final readonly class UpdateDomainHandler
|
|||||||
private MessageBusInterface $bus,
|
private MessageBusInterface $bus,
|
||||||
private WatchlistRepository $watchlistRepository,
|
private WatchlistRepository $watchlistRepository,
|
||||||
private DomainRepository $domainRepository,
|
private DomainRepository $domainRepository,
|
||||||
private RateLimiterFactory $rdapRequestsLimiter, private LoggerInterface $logger,
|
private LoggerInterface $logger,
|
||||||
) {
|
) {
|
||||||
$this->sender = new Address($mailerSenderEmail, $mailerSenderName);
|
$this->sender = new Address($mailerSenderEmail, $mailerSenderName);
|
||||||
}
|
}
|
||||||
@ -63,6 +62,7 @@ final readonly class UpdateDomainHandler
|
|||||||
* @throws ServerExceptionInterface
|
* @throws ServerExceptionInterface
|
||||||
* @throws MalformedDomainException
|
* @throws MalformedDomainException
|
||||||
* @throws ExceptionInterface
|
* @throws ExceptionInterface
|
||||||
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function __invoke(UpdateDomain $message): void
|
public function __invoke(UpdateDomain $message): void
|
||||||
{
|
{
|
||||||
@ -76,22 +76,17 @@ final readonly class UpdateDomainHandler
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$limiter = $this->rdapRequestsLimiter->create($rdapServer->getUrl());
|
|
||||||
$limit = $limiter->consume();
|
|
||||||
|
|
||||||
if (!$limit->isAccepted()) {
|
|
||||||
$retryAfter = $limit->getRetryAfter()->getTimestamp() - time();
|
|
||||||
|
|
||||||
$this->logger->warning('Security rate limit reached for this RDAP server', [
|
|
||||||
'url' => $rdapServer->getUrl(),
|
|
||||||
'retryAfter' => $retryAfter,
|
|
||||||
]);
|
|
||||||
|
|
||||||
throw new RecoverableMessageHandlingException('Rate limit reached', 0, null, $retryAfter);
|
|
||||||
}
|
|
||||||
|
|
||||||
$watchlist = $this->watchlistRepository->findOneBy(['token' => $message->watchlistToken]);
|
$watchlist = $this->watchlistRepository->findOneBy(['token' => $message->watchlistToken]);
|
||||||
|
|
||||||
|
if (!$this->RDAPService->isToBeUpdated($domain, false, null !== $watchlist->getConnector())) {
|
||||||
|
$this->logger->debug('The domain name is already present in the database and does not need to be updated at this time', [
|
||||||
|
'ldhName' => $domain->getLdhName(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$updatedAt = $domain->getUpdatedAt();
|
$updatedAt = $domain->getUpdatedAt();
|
||||||
$deleted = $domain->getDeleted();
|
$deleted = $domain->getDeleted();
|
||||||
|
|
||||||
@ -101,7 +96,6 @@ final readonly class UpdateDomainHandler
|
|||||||
* We send messages that correspond to the sending of notifications that will not be processed here.
|
* We send messages that correspond to the sending of notifications that will not be processed here.
|
||||||
*/
|
*/
|
||||||
$this->RDAPService->registerDomain($domain->getLdhName());
|
$this->RDAPService->registerDomain($domain->getLdhName());
|
||||||
$this->bus->dispatch(new DetectDomainChange($watchlist->getToken(), $domain->getLdhName(), $updatedAt));
|
|
||||||
} catch (DomainNotFoundException) {
|
} catch (DomainNotFoundException) {
|
||||||
$newDomain = $this->domainRepository->findOneBy(['ldhName' => $domain->getLdhName()]);
|
$newDomain = $this->domainRepository->findOneBy(['ldhName' => $domain->getLdhName()]);
|
||||||
|
|
||||||
@ -123,5 +117,10 @@ final readonly class UpdateDomainHandler
|
|||||||
* In this case, the domain name can no longer be updated. Unfortunately, there is nothing more that can be done.
|
* In this case, the domain name can no longer be updated. Unfortunately, there is nothing more that can be done.
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @var Watchlist $wl */
|
||||||
|
foreach ($domain->getWatchlists()->getIterator() as $wl) {
|
||||||
|
$this->bus->dispatch(new DetectDomainChange($wl->getToken(), $domain->getLdhName(), $updatedAt));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user