From 277fe41f616c2bca23dbf09353effb8769a637d9 Mon Sep 17 00:00:00 2001 From: Beno!t POLASZEK Date: Tue, 5 Dec 2023 12:24:58 +0100 Subject: [PATCH] Feat: Expose nb loaded items since last flush (#53) * feat: expose nb loaded items since last flush * feat: update LoggerRecipe with nb loaded items since last flush --- src/EtlState.php | 2 +- src/Recipe/LoggerRecipe.php | 4 ++-- tests/Unit/Recipe/LoggerRecipeTest.php | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/EtlState.php b/src/EtlState.php index 0820a85..0801e7e 100644 --- a/src/EtlState.php +++ b/src/EtlState.php @@ -23,7 +23,6 @@ final class EtlState */ public SplObjectStorage $nextTickCallbacks; - private int $nbLoadedItemsSinceLastFlush = 0; private bool $earlyFlush = false; /** @@ -38,6 +37,7 @@ public function __construct( public readonly int $currentItemIndex = -1, public readonly int $nbExtractedItems = 0, public readonly int $nbLoadedItems = 0, + public readonly int $nbLoadedItemsSinceLastFlush = 0, public readonly ?int $nbTotalItems = null, public readonly DateTimeImmutable $startedAt = new DateTimeImmutable(), public readonly ?DateTimeImmutable $endedAt = null, diff --git a/src/Recipe/LoggerRecipe.php b/src/Recipe/LoggerRecipe.php index 5d33319..127ac0c 100644 --- a/src/Recipe/LoggerRecipe.php +++ b/src/Recipe/LoggerRecipe.php @@ -127,9 +127,9 @@ public function decorate(EtlExecutor $executor): EtlExecutor ->onFlush( fn (FlushEvent $event) => $this->log( $event, - $event->early ? 'Flushing items (early)...' : 'Flushing items...', + $event->early ? 'Flushing {nb} items (early)...' : 'Flushing {nb} items...', [ - 'key' => $event->state->currentItemKey, + 'nb' => $event->state->nbLoadedItemsSinceLastFlush, 'state' => $event->state, ], ), diff --git a/tests/Unit/Recipe/LoggerRecipeTest.php b/tests/Unit/Recipe/LoggerRecipeTest.php index 237ddae..843098a 100644 --- a/tests/Unit/Recipe/LoggerRecipeTest.php +++ b/tests/Unit/Recipe/LoggerRecipeTest.php @@ -30,12 +30,12 @@ fn ($record) => $record->message->toContain('Extracting item')->and($record->level->toBe(Level::Debug)), fn ($record) => $record->message->toContain('Transformed item')->and($record->level->toBe(Level::Debug)), fn ($record) => $record->message->toContain('Loaded item')->and($record->level->toBe(Level::Debug)), - fn ($record) => $record->message->toContain('Flushing items (early)...')->and($record->level->toBe(Level::Info)), + fn ($record) => $record->message->toContain('Flushing {nb} items (early)...')->and($record->level->toBe(Level::Info)), fn ($record) => $record->message->toContain('Extracting item')->and($record->level->toBe(Level::Debug)), fn ($record) => $record->message->toContain('Transformed item')->and($record->level->toBe(Level::Debug)), fn ($record) => $record->message->toContain('Loaded item')->and($record->level->toBe(Level::Debug)), - fn ($record) => $record->message->toContain('Flushing items (early)...')->and($record->level->toBe(Level::Info)), - fn ($record) => $record->message->toContain('Flushing items...')->and($record->level->toBe(Level::Info)), + fn ($record) => $record->message->toContain('Flushing {nb} items (early)...')->and($record->level->toBe(Level::Info)), + fn ($record) => $record->message->toContain('Flushing {nb} items...')->and($record->level->toBe(Level::Info)), fn ($record) => $record->message->toContain('ETL complete.')->and($record->level->toBe(Level::Info)), ); });