Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Expose nb loaded items since last flush #53

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)),
);
});
Loading