-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🌟 Version 2.0 🌟 - Rewrite Chain Processor
- This optimizes the chain processor as the old version relied on a lot of StopItems - Allows ChainProcessor to output through generators the items. This is great to remove all limitations of the current sub chains. - ChainRepeatOperation now can handle more complex cases & asynchronous tasks.
- Loading branch information
Showing
22 changed files
with
522 additions
and
290 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
|
||
return RectorConfig::configure() | ||
->withPaths([ | ||
__DIR__ . '/old-docs', | ||
__DIR__ . '/src', | ||
]) | ||
// uncomment to reach your current PHP version | ||
// ->withPhpSets() | ||
->withTypeCoverageLevel(0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/Oliverde8/Component/PhpEtl/ChainOperation/FailSafeOperation.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Oliverde8\Component\PhpEtl\ChainOperation; | ||
|
||
use Oliverde8\Component\PhpEtl\ChainProcessor; | ||
use Oliverde8\Component\PhpEtl\Item\DataItemInterface; | ||
use Oliverde8\Component\PhpEtl\Item\GroupedItem; | ||
use Oliverde8\Component\PhpEtl\Item\ItemInterface; | ||
use Oliverde8\Component\PhpEtl\Item\StopItem; | ||
use Oliverde8\Component\PhpEtl\Model\ExecutionContext; | ||
|
||
class FailSafeOperation implements ChainOperationInterface, DetailedObservableOperation | ||
{ | ||
use SplittedChainOperationTrait; | ||
|
||
protected int $count = 0; | ||
|
||
public function __construct( | ||
protected readonly ChainProcessor $chainProcessor, | ||
protected readonly array $exceptionsToCatch, | ||
protected readonly int $nbAttempts, | ||
){} | ||
|
||
public function process(ItemInterface $item, ExecutionContext $context) | ||
{ | ||
if ($item instanceof StopItem) { | ||
foreach ($this->repeatOnItem($item, $context) as $newItem) {} | ||
return $item; | ||
} | ||
|
||
return new GroupedItem($this->repeatOnItem($item, $context)); | ||
} | ||
|
||
public function repeatOnItem(ItemInterface $inputItem, ExecutionContext $context): \Generator | ||
{ | ||
$nbAttempts = 0; | ||
do { | ||
try { | ||
foreach ($this->chainProcessor->processGenerator($inputItem, $context, withStop: false) as $newItem) { | ||
yield $newItem; | ||
} | ||
return; | ||
} catch (\Exception $exception) { | ||
$nbAttempts++; | ||
$exceptionHandled = false; | ||
foreach ($this->exceptionsToCatch as $exceptionType) { | ||
if ($exception instanceof $exceptionType) { | ||
$exceptionHandled = true; | ||
} | ||
} | ||
|
||
if (!$exceptionHandled || $nbAttempts >= $this->nbAttempts) { | ||
$context->getLogger()->error("Failed to handle exception in fail safe!", ['exception' => $exception]); | ||
throw $exception; | ||
} else { | ||
$context->getLogger()->warning("Handling exception with fail safe!", ['exception' => $exception, 'nbAttempts' => $nbAttempts]); | ||
} | ||
} | ||
} while ($nbAttempts < $this->nbAttempts); | ||
} | ||
} |
Oops, something went wrong.