refactor: create StatService

This commit is contained in:
Maël Gangloff
2024-08-25 03:31:09 +02:00
parent 4bb3ba7765
commit 0e1658f6fe
4 changed files with 35 additions and 24 deletions

View File

@@ -7,7 +7,6 @@ use App\Config\TriggerAction;
use App\Config\WebhookScheme;
use App\Entity\Domain;
use App\Entity\DomainEvent;
use App\Entity\Statistics;
use App\Entity\WatchList;
use App\Entity\WatchListTrigger;
use App\Message\ProcessDomainTrigger;
@@ -16,6 +15,7 @@ use App\Notifier\DomainOrderNotification;
use App\Notifier\DomainUpdateNotification;
use App\Repository\DomainRepository;
use App\Repository\WatchListRepository;
use App\Service\StatService;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpKernel\KernelInterface;
@@ -44,7 +44,8 @@ final readonly class ProcessDomainTriggerHandler
private LoggerInterface $logger,
private HttpClientInterface $client,
private MailerInterface $mailer,
private CacheItemPoolInterface $cacheItemPool
private CacheItemPoolInterface $cacheItemPool,
private StatService $statService
) {
$this->sender = new Address($mailerSenderEmail, $mailerSenderName);
}
@@ -86,7 +87,7 @@ final readonly class ProcessDomainTriggerHandler
$this->mailer->send($notification->asEmailMessage(new Recipient($watchList->getUser()->getEmail()))->getMessage());
$this->sendChatNotification($watchList, $notification);
Statistics::updateRDAPQueriesStat($this->cacheItemPool, 'stats.domain.purchased');
$this->statService->incrementStat('stats.domain.purchased');
} catch (\Throwable) {
$this->logger->warning('Unable to complete purchase. An error message is sent to user {username}.', [
'username' => $watchList->getUser()->getUserIdentifier(),
@@ -96,7 +97,7 @@ final readonly class ProcessDomainTriggerHandler
$this->mailer->send($notification->asEmailMessage(new Recipient($watchList->getUser()->getEmail()))->getMessage());
$this->sendChatNotification($watchList, $notification);
Statistics::updateRDAPQueriesStat($this->cacheItemPool, 'stats.domain.purchase.failed');
$this->statService->incrementStat('stats.domain.purchase.failed');
}
}
@@ -122,7 +123,7 @@ final readonly class ProcessDomainTriggerHandler
$this->sendChatNotification($watchList, $notification);
}
Statistics::updateRDAPQueriesStat($this->cacheItemPool, 'stats.alert.sent');
$this->statService->incrementStat('stats.alert.sent');
}
}
}