[4.x] Add batch tenancy queue bootstrapper
This PR adds a bootstrapper class for working with Laravel job batches. This fixes issues related to #547, where a Call to a member function prepare() on null exception gets thrown when the queue worker attempts to get a batch from the database for a different tenant than the previous one the queue worker processed. This is fixed by temporarily replacing the BatchRepository connection with the correct tenant connection, and then reverting it back when exiting the tenant context.
I don't think #547 is related, it's simply the same error message
Yeah, that is entirely possible. I still believe there is value in supporting the batch system though.
Thank you @Riley19280, this was a lifesaver for me trying to figure out why batch jobs would fail with the Call to a member function prepare() on null exception on subsequent dispatches when the first and second dispatch are from different tenants.
For what it's worth @stancl, I added this as a bootstrapper on v3 and it's been work flawless so far.
Codecov Report
Merging #874 (395d859) into master (f2c6408) will decrease coverage by
0.01%. The diff coverage is100.00%.
@@ Coverage Diff @@
## master #874 +/- ##
============================================
- Coverage 87.34% 87.32% -0.02%
- Complexity 408 415 +7
============================================
Files 112 114 +2
Lines 1130 1144 +14
============================================
+ Hits 987 999 +12
- Misses 143 145 +2
| Impacted Files | Coverage Δ | |
|---|---|---|
| src/Bootstrappers/BatchTenancyBootstrapper.php | 100.00% <100.00%> (ø) |
|
| ...e/TenantDatabaseManagers/SQLiteDatabaseManager.php | 76.47% <0.00%> (-8.15%) |
:arrow_down: |
| src/Listeners/DeleteTenantStorage.php | 100.00% <0.00%> (ø) |
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.
@abrardev99 Seems like GH was bugged again and some of my reviews didn't get submitted, they were "Pending". I submitted them now.
- Keep the property name
$batchRepository - Since we're using dependency injection, we shouldn't be using the
DB::facade in the code. Use DI for that as well. It should be something like Laravel'sDatabaseManagerI think
Keep the property name $batchRepository Since we're using dependency injection, we shouldn't be using the DB:: facade in the code. Use DI for that as well. It should be something like Laravel's DatabaseManager I think
Done.
Thanks for your work on this guys!