Repository navigation
feat: make #[Action] methods asynchronous with #[Async] - #428
Merged
Merged
Conversation
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Async Actions, phase 3 step 2: the
#[Async]attribute (design doc, "The #[Async] attribute").Pollora\Attributes\AsyncMethod or class target. Every option of
->async()is a named parameter:delay(seconds orDateInterval),via,onQueue;unique(trueor the lock duration),tries,backoff,asUser;captureandwhen(names of public methods of the class);keepMissing,except.Registration (
AsyncAttributeRegistrar)One place for both registration paths:
HookDiscoveryandAction::handle()(used by the post type and taxonomy discoveries).#[Async]is read on the method, otherwise on the class. A method's own#[Async]replaces the class's.#[Action]on a method: all are asynchronous, except the hooks inexcept.exceptthat the#[Action]attributes do not declare (checked against the whole class for a class-level#[Async]);captureorwhenmethod that is missing or not public;tries< 1, an invalidbackoff, orunique< 1, all checked before registration so nothing is half-applied.#[Async]on a#[Filter]is logged, and the filter still registers (a filter returns a value and cannot be deferred).#[Async]without#[Action]is logged too:HookDiscoverynow collects these methods.Fix on the way
HookServiceProviderdid not pass a logger toHookDiscovery, so registration errors (existing and new) went nowhere. It now receives the application's logger. This is in the CHANGELOG under Fixed.Tests
AsyncAttributeTest, 15 tests): options applied (checked withAsync::fake()),except,capture/when, no#[Async], class versus method, the six refused declarations, discovery (filter, orphan),Action::handle()with and without a logger, class context.Fixtures/AsyncAttributeFixtures.php, excluded from Rector: its dead-code rules had removed the empty, unused or private methods that carry the attributes under test.async.spec.ts, phase 3 exit criterion: "an action declared with attributes runs in a Laravel worker"):e2e-featuresplugin gets an#[Action]+#[Async(via: 'queue')]handler, fired from admin-ajax;artisan queue:work --once --stop-when-empty, then checks that the handler received its argument and itsAsyncContext, ran in the console, and had aLoggerInterfaceinjected by the container;artisan()helper insupport/site.ts(E2E_ARTISAN,ddev exec php artisanby default).