Skip to content

Commit

Permalink
FRW-9017 Added regeneration of oms process cache. (#11117)
Browse files Browse the repository at this point in the history
FRW-9017 Added regeneration of oms process cache.
  • Loading branch information
annakotiuk authored Oct 3, 2024
1 parent dc78a3b commit 0e57319
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 14 deletions.
6 changes: 4 additions & 2 deletions src/Spryker/Zed/Oms/Business/OmsFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,15 @@ public function triggerEventForOneOrderItem($eventId, $orderItemId, array $data
*
* @api
*
* @param bool $regenerateCache
*
* @return array<\Spryker\Zed\Oms\Business\Process\ProcessInterface>
*/
public function getProcesses()
public function getProcesses(bool $regenerateCache = false)
{
return $this->getFactory()
->createOrderStateMachineFinder()
->getProcesses();
->getProcesses($regenerateCache);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Spryker/Zed/Oms/Business/OmsFacadeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,11 @@ public function triggerEventForOneOrderItem($eventId, $orderItemId, array $data
*
* @api
*
* @param bool $regenerateCache
*
* @return array<\Spryker\Zed\Oms\Business\Process\ProcessInterface>
*/
public function getProcesses();
public function getProcesses(bool $regenerateCache = false);

/**
* Specification:
Expand Down
5 changes: 3 additions & 2 deletions src/Spryker/Zed/Oms/Business/OrderStateMachine/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,11 @@ public function __construct(

/**
* @param string $processName
* @param bool $regenerateCache
*
* @return \Spryker\Zed\Oms\Business\Process\ProcessInterface
*/
public function createProcess($processName)
public function createProcess($processName, bool $regenerateCache = false): ProcessInterface
{
if (isset(static::$processBuffer[$processName])) {
return static::$processBuffer[$processName];
Expand All @@ -135,7 +136,7 @@ public function createProcess($processName)
$process = $this->processCacheReader->getProcess($processName);
}

if (!$isProcessCached) {
if (!$isProcessCached || $regenerateCache) {
$process = $this->createMainProcess($processName);
$this->processCacheWriter->cacheProcess($process, $processName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@

namespace Spryker\Zed\Oms\Business\OrderStateMachine;

use Spryker\Zed\Oms\Business\Process\ProcessInterface;

interface BuilderInterface
{
/**
* @param string $processName
* @param bool $regenerateCache
*
* @return \Spryker\Zed\Oms\Business\Process\ProcessInterface
*/
public function createProcess($processName);
public function createProcess($processName, bool $regenerateCache = false): ProcessInterface;
}
6 changes: 4 additions & 2 deletions src/Spryker/Zed/Oms/Business/OrderStateMachine/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,16 @@ public function getItemsWithoutFlag(SpySalesOrder $order, $flag)
}

/**
* @param bool $regenerateCache
*
* @return array<\Spryker\Zed\Oms\Business\Process\ProcessInterface>
*/
public function getProcesses()
public function getProcesses(bool $regenerateCache = false)
{
$processes = [];
foreach ($this->activeProcesses as $processName) {
$builder = clone $this->builder;
$processes[$processName] = $builder->createProcess($processName);
$processes[$processName] = $builder->createProcess($processName, $regenerateCache);
}

return $processes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ public function getItemsWithFlag(SpySalesOrder $order, $flag);
public function getItemsWithoutFlag(SpySalesOrder $order, $flag);

/**
* @param bool $regenerateCache
*
* @return array<\Spryker\Zed\Oms\Business\Process\ProcessInterface>
*/
public function getProcesses();
public function getProcesses(bool $regenerateCache = false);

/**
* @param \Orm\Zed\Sales\Persistence\SpySalesOrderItem $orderItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected function configure(): void
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->getFacade()->getProcesses();
$this->getFacade()->getProcesses(true);

return static::CODE_SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,15 @@ public function testCreateProcessShouldReadFromCacheIfCacheIsEnabled(
* @dataProvider omsProcessCachingWriterDataProvider
*
* @param bool $cacheIsEnabled
* @param int $expectedReaderCalls
* @param bool $regenerateCache
* @param int|bool $expectedReaderCalls
* @param int $expectedWriterCalls
*
* @return void
*/
public function testCreateProcessShouldWriteToCacheIfCacheIsEnabled(
bool $cacheIsEnabled,
bool $regenerateCache,
int $expectedReaderCalls,
int $expectedWriterCalls
): void {
Expand Down Expand Up @@ -230,10 +232,10 @@ public function testCreateProcessShouldWriteToCacheIfCacheIsEnabled(

// Act
$this->tester->resetProcessBuffer();
$builder->createProcess('process-a');
$builder->createProcess('process-a', $regenerateCache);

$this->tester->resetProcessBuffer();
$builder->createProcess('process-a');
$builder->createProcess('process-a', $regenerateCache);
}

/**
Expand All @@ -242,13 +244,21 @@ public function testCreateProcessShouldWriteToCacheIfCacheIsEnabled(
protected function omsProcessCachingWriterDataProvider(): array
{
return [
'test when cache is enabled' => [
'test when cache is enabled and should be regenerated' => [
'cacheIsEnabled' => true,
'regenerateCache' => true,
'expectedReaderCalls' => 2,
'expectedWriterCalls' => 2,
],
'test when cache is enabled and should not be regenerated' => [
'cacheIsEnabled' => true,
'regenerateCache' => false,
'expectedReaderCalls' => 2,
'expectedWriterCalls' => 1,
],
'test when cache is disabled' => [
'cacheIsEnabled' => false,
'regenerateCache' => false,
'expectedReaderCalls' => 0,
'expectedWriterCalls' => 0,
],
Expand Down

0 comments on commit 0e57319

Please sign in to comment.