Skip to content

Commit e8c697c

Browse files
committed
feat: Etl progress information is now saved on the execution entity(updated every 5 seconds)
1 parent 8867b59 commit e8c697c

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# 1.1.0
22

3-
- :star2: Support for php-etl 1.1 new operations has been added.
3+
- :star2: Support for php-etl 1.2 new operations has been added. (Skipped 1.1)
44
- :star2: Support for symfony 6.0 has been added.
55
- :star2: Support for using input parameters in operation options has been added.
6+
- :star2: Added support to the command line to displayt ETL progress, (feature from php-etl 1.2)
7+
- :star2: Etl progress information is now saved on the execution entity(updated every 5 seconds)
68
- :collision: All operations are no longer built during DI compilation. This should improve peformance of cache warmup.
79
- :collision: Support for Symfony 4.4 has been dropped.
810
- :collision: Support for php 7.4 has been dropped.

Entity/EtlExecution.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
/**
99
* @ORM\Entity(repositoryClass=EtlExecutionRepository::class)
10+
*
1011
*/
1112
class EtlExecution
1213
{
@@ -255,7 +256,7 @@ public function setRunTime(int $runTime): void
255256
{
256257
$this->runTime = $runTime;
257258
}
258-
259+
259260
/**
260261
* @return mixed
261262
*/
@@ -286,6 +287,10 @@ public function setDefinition(string $definition): self
286287

287288
public function getStepStats(): ?string
288289
{
290+
if ($this->stepStats == "[]") {
291+
// Legacy json stuff.
292+
return null;
293+
}
289294
return $this->stepStats;
290295
}
291296

Services/ChainProcessorsManager.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Oliverde8\PhpEtlBundle\Exception\UnknownChainException;
88
use Oliverde8\PhpEtlBundle\Factory\ChainFactory;
99
use Oliverde8\PhpEtlBundle\Repository\EtlExecutionRepository;
10+
use function Clue\StreamFilter\fun;
1011

1112
class ChainProcessorsManager
1213
{
@@ -124,7 +125,18 @@ public function executeFromEtlEntity(EtlExecution $execution, iterable $iterator
124125
];
125126

126127
// Start the process.
127-
$processor->process($iterator, $params, $observerCallback);
128+
$observerProcessTime = 0;
129+
$processor->process($iterator, $params, function (array $operationStates, int $processedItems, int $returnedItems, bool $hasFinished = false) use ($observerCallback, &$observerProcessTime, $execution) {
130+
$observerCallback($operationStates, $processedItems, $returnedItems, $hasFinished);
131+
132+
if ((time() - $observerProcessTime) > 5) {
133+
$execution = $this->etlExecutionRepository->find($execution->getId());
134+
$execution->setStepStats(serialize($operationStates));
135+
$this->etlExecutionRepository->save($execution);
136+
137+
$observerProcessTime = time();
138+
}
139+
});
128140
$execution = $this->etlExecutionRepository->find($execution->getId());
129141
$execution->setStatus(EtlExecution::STATUS_SUCCESS);
130142
} catch (\Throwable $exception) {
@@ -136,7 +148,6 @@ public function executeFromEtlEntity(EtlExecution $execution, iterable $iterator
136148
} finally {
137149
$execution->setEndTime(new \DateTime());
138150
$execution->setRunTime(time() - $execution->getStartTime()->getTimestamp());
139-
$execution->setStepStats('[]'); // To be developped
140151
$this->etlExecutionRepository->save($execution);
141152
}
142153
}

0 commit comments

Comments
 (0)