<?php
namespace App\Service\App\Merchant\EventListener;
use App\Background\Data\CustomerStatData;
use App\Core\BackgroundWork\Contract\IClient;
use App\Service\App\Merchant\Event\UpdateCustomerStatEvent;
class UpdateCustomerStatListener
{
/**
* Background work client
*
* @var IClient
*/
private IClient $backgroundWorkClient;
/**
* @param IClient $backgroundWorkClient
*/
public function __construct(IClient $backgroundWorkClient)
{
$this->backgroundWorkClient = $backgroundWorkClient;
}
/**
* Handle event
*
* @param UpdateCustomerStatEvent $event
* @return void
*/
public function onUpdateStat(UpdateCustomerStatEvent $event): void
{
$this->backgroundWorkClient->add(
new CustomerStatData($event->getMerchant(), $event->getCustomerId())
);
$this->backgroundWorkClient->runJobs();
}
}