Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/peterfox/laravel-queue-batch-exp
https://github.com/peterfox/laravel-queue-batch-exp
Last synced: 5 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/peterfox/laravel-queue-batch-exp
- Owner: peterfox
- Created: 2023-10-11T20:30:53.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-11T20:31:12.000Z (about 1 year ago)
- Last Synced: 2024-10-12T11:34:37.014Z (about 1 month ago)
- Language: PHP
- Size: 74.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Batch experiment with Laravel
The purpose of this repo is to prove that you can add to a queue batch.
What will happen is:
1. Send a batch of two to the queue.
2. Once executed the `then` closure will be executed.
3. If less than 3 jobs have been executed, another is added to the batch.## Setup
Setup the .env file
```dotenv
DB_CONNECTION=sqliteQUEUE_CONNECTION=database
```Migrate a SQLite DB.
```shell
php artisan migrate
```Then run the queue worker in one terminal
```shell
php artisan queue:work
```Then run the following to fire off the batch
```shell
php artisan qt
```You should see the results in Ray.
## Conclusion
1. Laravel batches can be added to from Then closure.
2. Laravel batches reset the `finished_at` value when adding new
jobs to the batch from the Then closure. This happens in the
`\Illuminate\Bus\DatabaseBatchRepository`.
3. This can be dangerous if the Then closure can end up in a loop
adding additional jobs.
4. One downside is that the `finished_at` is saved before the addition
of any new jobs making it potentially seem like the batch is complete.
Instead, there needs to be a secondary notice somewhere.