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

TASK: Yield events to publish in workspace command handler #5315

Conversation

mhsdesign
Copy link
Member

@mhsdesign mhsdesign commented Oct 23, 2024

1.) Allow command handlers to yield EventsToPublish

Using generators will allow us to omit the direct publishing via ->publishEvents or sub command handling via ->handle

For exception cases - on a ConcurrencyException - it will be possible to notice the failure in the command handler and act accordingly (by emitting another event and than raising another error).
If try catch is used the ConcurrencyException will be rethrown into the outer world:

try {
   yield EventsToPublish();
} catch (ConcurrencyException $e) {
   yield $restoreState();
   throw $e;
}

Catchups will be invoked after each yield to ensure that the system is atomic.

2.) Cleanup RebasableToOtherWorkspaceInterface extraction
And enforce type of RebasableToOtherWorkspaceInterface earlier.

To be noted: The rebase and discard operation previously only required fromArray to be implemented, now we also strict check against: RebasableToOtherWorkspaceInterface

3.) Avoid use of sub commands in WorkspaceCommandHandler
rebase, discard & publish individual will be migrated via #5301

Upgrade instructions

Review instructions

Checklist

  • Code follows the PSR-2 coding style
  • Tests have been created, run and adjusted as needed
  • The PR is created against the lowest maintained branch
  • Reviewer - PR Title is brief but complete and starts with FEATURE|TASK|BUGFIX
  • Reviewer - The first section explains the change briefly for change-logs
  • Reviewer - Breaking Changes are marked with !!! and have upgrade-instructions

Using generators will allow us to omit the direct publishing via ->publishEvents or sub command handling via ->handle

For exception cases - on a ConcurrencyException - it will be possible to notice the failure in the command handler and act accordingly (by emitting another event and than raising another error).
If no error strategy is provided the `ConcurrencyException` will be rethrown into the outer world:

```php
$publishResult = yield new EventsToPublish(...);

if ($publishResult instanceof EventsToPublishFailed) {
   yield new EventsToPublish(...);
   throw new BaseWorkspaceHasBeenModifiedInTheMeantime();
}
```

Catchups will be invoked after each yield to ensure that the system is atomic.
And enforce type of `RebasableToOtherWorkspaceInterface` earlier.

To be noted: The rebase and discard operation previously only required `fromArray` to be implemented, now we also strict check against: RebasableToOtherWorkspaceInterface
rebase, discard & publish individual will be migrated via
Copy link
Member

@bwaidelich bwaidelich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great already! Some first comments

kitsunet and others added 2 commits October 23, 2024 14:08
…/ContentStreamForking/01-ForkContentStream_ConstraintChecks.feature

Co-authored-by: Bastian Waidelich <b.waidelich@wwwision.de>
@mhsdesign mhsdesign mentioned this pull request Oct 23, 2024
6 tasks
@mhsdesign mhsdesign requested a review from kitsunet October 24, 2024 16:24
@kitsunet kitsunet merged commit 6728d5e into neos:9.0 Oct 24, 2024
9 checks passed
@mhsdesign mhsdesign deleted the task/schnappsidee-zwo-yield-events-to-publish-in-workspace-command-handler branch October 24, 2024 16:25
mhsdesign added a commit to mhsdesign/neos-development-collection that referenced this pull request Oct 26, 2024
…command handler

Before 29a27de we required the ->throw() behaviour of neos#5315 to catch the `ConcurrencyException` inside in the command handler.
@mhsdesign
Copy link
Member Author

fyi as we do a rebase now instead of failing if a rebase is necessary, we dont need the error handling:

    try {
        yield $publishContentStream;
    } catch (ConcurrencyException $exception) {
        yield $this->reopenContentStream(
            $workspace->currentContentStreamId,
            $currentWorkspaceContentStreamState,
            $commandHandlingDependencies
        );

        throw new BaseWorkspaceHasBeenModifiedInTheMeantime(sprintf(
            'The base workspace has been modified in the meantime; please rebase.'
            . ' Expected version %d of source content stream %s',
            $publishContentStream->expectedVersion->value,
            $baseWorkspace->currentContentStreamId
        ));
    }

and thus i removed the complexity -> 3679157

neos-bot pushed a commit to neos/contentrepository-core that referenced this pull request Oct 28, 2024
…command handler

Before 394db57 we required the ->throw() behaviour of neos/neos-development-collection#5315 to catch the `ConcurrencyException` inside in the command handler.
mhsdesign added a commit to mhsdesign/neos-development-collection that referenced this pull request Nov 9, 2024
… version instead

Also readd lost documentation and simplifies the `handle`

The ->throw logic was initially introduced via

neos#5315

but then removed again as we thought it was no longer needed.
neos-bot pushed a commit to neos/contentrepository-core that referenced this pull request Nov 12, 2024
… version instead

Also readd lost documentation and simplifies the `handle`

The ->throw logic was initially introduced via

neos/neos-development-collection#5315

but then removed again as we thought it was no longer needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants