Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure events are sent from queues when using Laravel Vapor #511

Merged
merged 3 commits into from
Jan 6, 2023

Conversation

imjoehaines
Copy link
Member

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:

  1. flush events in 'after' and 'exceptionOccurred' in order to send any events created during the execution of a job
  2. 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
  3. 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

Currently we never flush the queue of events when using Laravel Vapor
because it does not call our shutdown function or the 'looping' event

We need to:

1. flush events in 'after' and 'exceptionOccurred' in order to send any
   events created during the execution of a job
2. 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
3. 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 stops breadcrumbs leaking between jobs
@imjoehaines imjoehaines merged commit 5120fd7 into next Jan 6, 2023
@imjoehaines imjoehaines deleted the laravel-vapor branch January 6, 2023 10:51
@imjoehaines imjoehaines mentioned this pull request Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants