[9.x] Release lock for job implementing ShouldBeUnique that is dispatched afterResponse() - #46806
Conversation
ShouldBeUnique that is dispatched afterResponse()
|
Is this not as simple as just changing
public function dispatchAfterResponse($command, $handler = null)
{
$this->container->terminating(function () use ($command, $handler) {
$this->dispatchSync($command, $handler);
});
} |
You're right. I've reverted the other changes I made, though I kept the change to Tweaked the test cases slightly to use both Job::dispatch()->afterResponse() and Job::dispatchAfterResponse(); |

To resolve #46537
Dispatchable@dispatchAfterResponse()so thatPendingDispatch@shouldDispatch()checks for lock, rather than just pushing immediately to the Application::$terminatingCallbacks array. Could move this to a separate PR, as maybe you would consider it a breaking change. Seems kind of strange thatJob::dispatchAfterResponse()doesn't check for uniqueness, butJob::dispatch()->afterResponse()does.CallQueuedHandler@call()to its own methodCallQueuedHandler@handle(). I named the methodhandle()so that it could be more easily used withBus\Dispatcher@dispatchNow()(which is expecting the$handlerargument to implement either__invoke()orhandle().Jobs dispatched after response should now also be routed through middleware as well. Might make sense to add a test case for that, just let me know.