Thursday, May 30, 2019

The Laravel Synchronous Queue

Using queues for asynchronous processing is one of my favorite tricks for offloading hard work from web servers. When working with Laravel recently I was pleased to find that it supports beanstalkd out of the box. I've got opinions about frameworks with Opinions but I did find one thing I really liked in the way Laravel uses queues: the sync queue option that runs your queue synchronously on your development platform so you can develop and debug your work, then switch the queue platform you use later.

It's quite tricky to debug Laravel "Jobs" as they call the worker code — if errors occur, they don't show up in the general output. You can use error_log() and see that output, but if there's a PHP error, you won't see that error. However you can configure the QUEUE_CONNECTION in .env to be "sync". The sync queue type is not asynchronous at all — instead of putting the job onto your chosen queue backend, it goes right ahead and processes the job in the current thread of execution. This completely defeats the object of using a queue but is a brilliant approach for debugging how the data passes from the dispatching context (where the data is put into the job and onto a queue) to the worker context (where the job comes back off the queue and actually gets processed) and how the job is processed.



from DZone.com Feed http://bit.ly/2VYCHI2

No comments:

Post a Comment