Skip to content

Commit

Permalink
Run syncing cases distributed
Browse files Browse the repository at this point in the history
  • Loading branch information
rjzondervan committed Feb 7, 2024
1 parent c9b7ec5 commit 4768e49
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
3 changes: 2 additions & 1 deletion Installation/installation.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@
{
"reference": "https://development.zaaksysteem.nl/action/xxllnc.Zaak.action.json",
"actionHandler": "CommonGateway\\XxllncZGWBundle\\ActionHandler\\ZaakHandler",
"listens": ["xxllnc.cronjob.trigger"]
"listens": ["xxllnc.cronjob.trigger", "xxllnc.case.received"],
"async": true
},
{
"reference": "https://development.zaaksysteem.nl/action/xxllnc.ZaakType.action.json",
Expand Down
50 changes: 33 additions & 17 deletions src/Service/ZaakService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use App\Entity\Gateway as Source;
use App\Entity\ObjectEntity;
use App\Event\ActionEvent;
use App\Service\SynchronizationService;
use CommonGateway\CoreBundle\Service\GatewayResourceService;
use CommonGateway\CoreBundle\Service\MappingService;
Expand All @@ -23,6 +24,7 @@
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use Symfony\Component\Console\Style\SymfonyStyle;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Log\LoggerInterface;

class ZaakService
Expand Down Expand Up @@ -88,6 +90,11 @@ class ZaakService
*/
private LoggerInterface $logger;

/**
* @var EventDispatcherInterface The event dispatcher.
*/
private EventDispatcherInterface $eventDispatcher;


/**
* __construct.
Expand All @@ -100,7 +107,8 @@ public function __construct(
ZaakTypeService $zaakTypeService,
GatewayResourceService $resourceService,
MappingService $mappingService,
LoggerInterface $pluginLogger
LoggerInterface $pluginLogger,
EventDispatcherInterface $eventDispatcher
) {
$this->entityManager = $entityManager;
$this->synchronizationService = $synchronizationService;
Expand All @@ -110,6 +118,7 @@ public function __construct(
$this->resourceService = $resourceService;
$this->mappingService = $mappingService;
$this->logger = $pluginLogger;
$this->eventDispatcher = $eventDispatcher;

}//end __construct()

Expand Down Expand Up @@ -504,22 +513,29 @@ public function zaakHandler(?array $data = [], ?array $configuration = [])
$createdZaakCount = 0;
$flushCount = 0;
foreach ($xxllncCases as $case) {
if ($this->syncCase($case) instanceof ObjectEntity === false) {
isset($this->style) === true && $this->style->error("Could not sync a case");
$this->logger->error("Could not sync a case");

continue;
}

$createdZaakCount = ($createdZaakCount + 1);
$flushCount = ($flushCount + 1);

// Flush every 20
if ($flushCount == 20) {
$this->entityManager->flush();
$this->entityManager->flush();
$flushCount = 0;
}//end if
$event = new ActionEvent(
'commongateway.action.event',
['caseId' => $case['reference']],
'xxllnc.case.received'
);
$this->eventDispatcher->dispatch($event, 'commongateway.action.event');

// if ($this->syncCase($case) instanceof ObjectEntity === false) {
// isset($this->style) === true && $this->style->error("Could not sync a case");
// $this->logger->error("Could not sync a case");
//
// continue;
// }
//
// $createdZaakCount = ($createdZaakCount + 1);
// $flushCount = ($flushCount + 1);
//
// // Flush every 20
// if ($flushCount == 20) {
// $this->entityManager->flush();
// $this->entityManager->flush();
// $flushCount = 0;
// }//end if
}//end foreach

isset($this->style) === true && $this->style->success("Created $createdZaakCount zaken from the $caseCount fetched cases");
Expand Down

0 comments on commit 4768e49

Please sign in to comment.