Skip to content

Commit

Permalink
Merge pull request #4952 from mhsdesign/task/cleanupThingsRegardingEv…
Browse files Browse the repository at this point in the history
…ents

TASK: Export event cleanup and error handling for catchupd events
  • Loading branch information
mhsdesign committed Apr 3, 2024
2 parents 6a37041 + a68fbeb commit c05516c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,13 @@ public function denormalize(Event $event): EventInterface
$eventDataAsArray = json_decode($event->data->value, true, 512, JSON_THROW_ON_ERROR);
} catch (\JsonException $exception) {
throw new \InvalidArgumentException(
sprintf('Failed to decode data of event "%s": %s', $event->id->value, $exception->getMessage()),
sprintf('Failed to decode data of event with type "%s" and id "%s": %s', $event->type->value, $event->id->value, $exception->getMessage()),
1651839461
);
}
assert(is_array($eventDataAsArray));
if (!is_array($eventDataAsArray)) {
throw new \RuntimeException(sprintf('Expected array got %s', $eventDataAsArray));
}
/** {@see EventInterface::fromArray()} */
$eventInstance = $eventClassName::fromArray($eventDataAsArray);
return match ($eventInstance::class) {
Expand Down
6 changes: 5 additions & 1 deletion Neos.ContentRepository.Core/Classes/Projection/CatchUp.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ public function run(EventStreamInterface $eventStream): SequenceNumber
if ($eventEnvelope->sequenceNumber->value <= $highestAppliedSequenceNumber->value) {
continue;
}
($this->eventHandler)($eventEnvelope);
try {
($this->eventHandler)($eventEnvelope);
} catch (\Exception $e) {
throw new \RuntimeException(sprintf('Exception while catching up to sequence number %d', $eventEnvelope->sequenceNumber->value), 1710707311, $e);
}
$iteration++;
if ($this->batchSize === 1 || $iteration % $this->batchSize === 0) {
if ($this->onBeforeBatchCompletedHook) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,39 @@
final readonly class ExportedEvent implements \JsonSerializable
{
/**
* The Neos.ContentRepository.Core's domain events require the payload to be a json array string
* {@see \Neos\ContentRepository\Core\EventStore\EventInterface}
* This exporter will enforce this as well (by using array as payload type).
*
* @param array<mixed> $payload
* @param array<mixed> $metadata
*/
public function __construct(
public string $identifier,
public string $type,
public array $payload, // TODO: string
public array $payload,
public array $metadata,
) {}
) {
}

public static function fromRawEvent(Event $event): self
{
return new self(
$event->id->value,
$event->type->value,
\json_decode($event->data->value, true),
\json_decode($event->data->value, true, 512, JSON_THROW_ON_ERROR),
$event->metadata?->value ?? [],
);
}

public static function fromJson(string $json): self
{
try {
///** @var array{identifier: string, type: string, payload: array<mixed>, metadata: array<mixed>} $data */
/** @var array<mixed> $data */
/** @var array{identifier: string, type: string, payload: array<mixed>, metadata: array<mixed>} $data */
$data = json_decode($json, true, 512, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new \InvalidArgumentException(sprintf('Failed to decode JSON "%s": %s', $json, $e->getMessage()), 1638432979, $e);
}
assert(isset($data['identifier']) && is_string($data['identifier']));
assert(isset($data['type']) && is_string($data['type']));
assert(isset($data['payload']) && is_array($data['payload']));
assert(isset($data['metadata']) && is_array($data['metadata']));
return new self(
$data['identifier'],
$data['type'],
Expand Down Expand Up @@ -80,12 +80,8 @@ public function toJson(): string
}
}

/**
* @return array{identifier: string, type: string, payload: array<mixed>, metadata?: ?array<mixed>, streamName?: string, version?: int, sequenceNumber?: int, recordedAt?: string}
*/
public function jsonSerialize(): array
public function jsonSerialize(): mixed
{
/** @phpstan-ignore-next-line */
return get_object_vars($this);
}
}

0 comments on commit c05516c

Please sign in to comment.