lucid icon indicating copy to clipboard operation
lucid copied to clipboard

Fix/v10.x

Open NayThuKhant opened this issue 1 year ago • 4 comments

In Laravel 10.x, the flow of dispatch helper function changed a bit and lucid wont be working on it anymore. To solve it, let me create this PR.

  • run method of Lucid\Bus\UnitDispatcher.php &
  • serve method of Lucid\Bus\ServesFeature.php

will now be using dispatchSync() not the dispatch() that lucid used previously.

NayThuKhant avatar Mar 20 '23 12:03 NayThuKhant

@NayThuKhant Great job. Problem with the PR is that dispatchSync will always perform the job/feature synchronously. One of the Lucid features is that jobs/features can be dispatched for delayed/async processing. Laravel does not return the result anymore after a dispatch but it could be an improvement to choose between sync/async. The consequence of async dispatch is that the result cannot be used, but that is the way async works.

chris-rs avatar May 26 '23 09:05 chris-rs

@NayThuKhant Great job. Problem with the PR is that dispatchSync will always perform the job/feature synchronously. One of the Lucid features is that jobs/features can be dispatched for delayed/async processing. Laravel does not return the result anymore after a dispatch but it could be an improvement to choose between sync/async. The consequence of async dispatch is that the result cannot be used, but that is the way async works.

I think we can still use runInQueue if only we want to run a job synchronously, isn't it?

    public function runInQueue($unit, array $arguments = [], $queue = 'default')
    {
        // instantiate and queue the unit
        $reflection = new ReflectionClass($unit);
        $instance = $reflection->newInstanceArgs($arguments);
        $instance->onQueue((string)$queue);

        return $this->dispatch($instance);
    }

NayThuKhant avatar Jun 30 '23 06:06 NayThuKhant

Hello again, Any chance a contributor to revive this project. It is an important library. If no feature are added, at least keep up to date with the iteration of Laravel version.

ntgraph avatar Mar 06 '24 22:03 ntgraph

@NayThuKhant We're running into a similar issue with the (https://github.com/ksimenic/lucid) fork because of the dispatchSync change. The difficulty with having to use the runInQueue method is that you need to know the queue name to dispatch your job or operation to.

We use separate queues that are configured in the global queue configuration, thus resulting in jobs being sent to the wrong queue. (basically any queue that is named different than default will go wrong)

In the old situation, they would be dispatched to the correct queue (as configured in the laravel queue config)

websmurf avatar Mar 29 '24 15:03 websmurf