Skip to content

Commit

Permalink
Merge pull request #4452 from neos/feature/4200-replay-progress-bar
Browse files Browse the repository at this point in the history
FEATURE: Progress bar for projection replay
  • Loading branch information
skurfuerst authored Sep 1, 2023
2 parents 37bf63e + b5f4f8a commit 71e64ed
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
5 changes: 4 additions & 1 deletion Neos.ContentRepository.Core/Classes/ContentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,11 @@ public function catchUpProjection(string $projectionClassName, CatchUpOptions $o
$eventStream = $eventStream->withMaximumSequenceNumber($options->maximumSequenceNumber);
}

$eventApplier = function (EventEnvelope $eventEnvelope) use ($projection, $catchUpHook) {
$eventApplier = function (EventEnvelope $eventEnvelope) use ($projection, $catchUpHook, $options) {
$event = $this->eventNormalizer->denormalize($eventEnvelope->event);
if ($options->progressCallback !== null) {
($options->progressCallback)($event, $eventEnvelope);
}
if (!$projection->canHandle($event)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

namespace Neos\ContentRepository\Core\Projection;

use Closure;
use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\EventStore\EventInterface;
use Neos\EventStore\Model\Event\SequenceNumber;
use Neos\EventStore\Model\EventEnvelope;

/**
* Options for {@see ContentRepository::catchUpProjection()}
Expand All @@ -16,9 +19,11 @@ final class CatchUpOptions
{
/**
* @param SequenceNumber|null $maximumSequenceNumber If specified the catch-up will stop at the specified {@see SequenceNumber}
* @param Closure(EventInterface $event, EventEnvelope $eventEnvelope): void|null $progressCallback If specified the given closure will be invoked for every event with the current {@see EventInterface} and {@see EventEnvelope} passed as arguments
*/
private function __construct(
public readonly ?SequenceNumber $maximumSequenceNumber,
public readonly ?Closure $progressCallback,
) {
}

Expand All @@ -30,11 +35,12 @@ private function __construct(
*/
public static function create(
SequenceNumber|int|null $maximumSequenceNumber = null,
Closure|null $progressCallback = null,
): self {
if (is_int($maximumSequenceNumber)) {
$maximumSequenceNumber = SequenceNumber::fromInteger($maximumSequenceNumber);
}
return new self($maximumSequenceNumber);
return new self($maximumSequenceNumber, $progressCallback);
}


Expand All @@ -46,9 +52,11 @@ public static function create(
*/
public function with(
SequenceNumber|int|null $maximumSequenceNumber = null,
Closure|null $progressCallback = null,
): self {
return self::create(
$maximumSequenceNumber ?? $this->maximumSequenceNumber,
$progressCallback ?? $this->progressCallback,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,18 @@ public function replayCommand(string $projection, string $contentRepository = 'd

if (!$quiet) {
$this->outputLine('Replaying events for projection "%s" of Content Repository "%s" ...', [$projection, $contentRepositoryId->value]);
// TODO start progress bar
$this->output->progressStart();
}
$options = CatchUpOptions::create();
$options = CatchUpOptions::create(
progressCallback: fn () => $this->output->progressAdvance(),
);
if ($until > 0) {
$options = $options->with(maximumSequenceNumber: SequenceNumber::fromInteger($until));
}
$projectionService->replayProjection($projection, $options);
if (!$quiet) {
// TODO finish progress bar
$this->output->progressFinish();
$this->outputLine();
$this->outputLine('<success>Done.</success>');
}
}
Expand Down

0 comments on commit 71e64ed

Please sign in to comment.