Has the following structure:
-
Presentation Level:
Web Interface, REST API and command prompt - all call only OrderService.
-
Application Layer:
class OrderService { private $em; private $repository; private $calculator; public function __construct( \Doctrine\ORM\EntityManagerInterface $em; ClientRepositoryInterface $repository, cumulativeDiscountCalculator $calculator } { $this->em = $em; $this->repository = $repository; $this->calculator = $calculator; } public function calculateCumulativeDiscount($id) { $this->em->beginTransaction(); try { $client = $this->repository->findClient(); $this->calculator->calculate($client); $this->em->flush(); $this->em->commit(); } catch (\Exception $e) { $this->em->rollback(); throw $e; } } }
-
Model layer:
interface ClientInterface { public function setDiscount($discount); } interface ClientRepositoryInterface { public function findClient($id); public function findClientsByDataRange($from, $to); } class cumulativeDiscountCalculator { public function calculate(ClientInterface $client) { $client->setDiscount(mt_rand(1, 50)); } }
-
Infrastructure Layer:
PHP Doctrine 2 - implement ClientRepositoryInterface.
My task - perform calculation discounts for a collection of clients. (method ClientRepositoryInterface::findClientsByDataRange returns collection for processing)
The problem is that I need to handle up to 100,000 records. I know how to do this technically, but how to do it in terms of DDD? The following questions arise:
- Which layer to use for batch processing?
- How to collect the results of actions: errors, count successful clients, etc?
- Where to set transaction boundaries(every N clients - commit and begin a new transaction)?
- I have about 10-20 batch operations, it may make sense any structure to develop?