Skip to content

Commit

Permalink
Feat: Expose nb loaded items since last flush (#53)
Browse files Browse the repository at this point in the history
* feat: expose nb loaded items since last flush

* feat: update LoggerRecipe with nb loaded items since last flush
  • Loading branch information
bpolaszek authored Dec 5, 2023
1 parent 2924577 commit 277fe41
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/EtlState.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ final class EtlState
*/
public SplObjectStorage $nextTickCallbacks;

private int $nbLoadedItemsSinceLastFlush = 0;
private bool $earlyFlush = false;

/**
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/Recipe/LoggerRecipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
),
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Recipe/LoggerRecipeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
);
});

0 comments on commit 277fe41

Please sign in to comment.