Download the PHP package ngmy/laravel-job-response without Composer
On this page you can find all versions of the php package ngmy/laravel-job-response. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ngmy/laravel-job-response
More information about ngmy/laravel-job-response
Files in ngmy/laravel-job-response
Package laravel-job-response
Short Description Add responses to Laravel Jobs - allowing your application to wait for a response from a dispatched job.
License MIT
Homepage https://github.com/ngmy/laravel-job-response
Informations about the package laravel-job-response
Laravel Job Response - Making your jobs respond
Have you ever needed to run a Laravel job (or multiple jobs), wait for the response and then use that response? This is exactly the functionality this package provides.
Installation
You can install the package via Composer:
Requirements
- PHP >= 8.1
- Laravel >= 10.0
Usage
In your Job
use the CanRespond
trait and add implement the JobCanRespond
contract:
Then in your Service/Controller/elsewhere, await a response from your job:
Or alternatively, run multiple jobs and await the responses:
Responses
By default, the package responds in three ways:
ResponseCollection
- When multiple responses are expected, a ResponseCollection will be returned containingResponse
and/orExceptionResponse
objects.Response
- A successful response object.ExceptionResponse
- When a job fails the exception is caught and passed back.
(Optional) Handling Exceptions
By default a ExceptionResponse
object is created. However, this can lead to some extra boilerplate code to handle
this, so instead we've an optional method available that will re-throw these exceptions.
To enable this, use the Facade to update the throwExceptionOnFailure
flag:
Now whenever a await is issued, if an exception is encountered from the job, a JobFailedException
will be raised:
Methods
Troubleshooting
There are a few quirks within Laravel that you may run into with this package:
- When running with a
sync
driver, Exceptions will not be caught - this is because Laravel does not natively catch them with the Sync driver and it is impossible for our package to pick them up. If you need to handle exceptions with this driver, use$job->fail($exception);
instead.
Testing
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-job-response with dependencies
ext-json Version *
ext-redis Version *
laravel/framework Version ^10.0 || ^11.0