Currently we never flush events in queued jobs when using Laravel Vapor because it does not call our shutdown function or fire the 'looping' event
To fix this, we need to:
flush events in 'after' and 'exceptionOccurred' in order to send any events created during the execution of a job
disable batch sending in 'after' and 'exceptionOccurred' so that any events created when a job finishes get sent synchronously. Otherwise we'd fail to send these events if the queue worker doesn't run another job
Re-enable batch sending in 'before' if we previously disabled it. This allows users to get the performance benefits of batch sending while their job is running (though it's much less relevant in a queue process)
This ensures that events created in a job are sent (when we call flush) and events created after a job are sent (as they are sent synchronously)
This PR also fixes breadcrumbs leaking between jobs; they are now cleared in the 'before' event on Laravel Vapor
Testing
Unfortunately this can't really be tested (short of running Vapor on CI) because these changes are specific to the way queues workers behave on Vapor. Any unit test would only prove the code is run as written, not that this actually works when run on Vapor
Goal
Currently we never flush events in queued jobs when using Laravel Vapor because it does not call our shutdown function or fire the 'looping' event
To fix this, we need to:
This ensures that events created in a job are sent (when we call
flush
) and events created after a job are sent (as they are sent synchronously)This PR also fixes breadcrumbs leaking between jobs; they are now cleared in the 'before' event on Laravel Vapor
Testing
Unfortunately this can't really be tested (short of running Vapor on CI) because these changes are specific to the way queues workers behave on Vapor. Any unit test would only prove the code is run as written, not that this actually works when run on Vapor