Make Vendure serverless proof
See original GitHub issueIs your feature request related to a problem? Please describe. Most (if not all?) serverless environments don’t allow processing outside the requestcontext. Vendure’s event handling has some async processes that occur outside the requestcontext. For examaple the apply-collection-filters
Event handling occurs after a response has been sent, because event.publish() is fire and forget (as it should be).
Describe the solution you’d like It would be nice if we can somehow be sure that no background tasks are running when a response has been returned.
Describe alternatives you’ve considered
One option I see is to be able to implement our own remote eventBus
strategy. We could do await eventBus.publish()
and be sure that the event is published. Event handling can be done similar to how worker Job’s are handled: in their own async request context if that’s what’s implemented in the implemented ‘eventbus strategy’.
A workaround for Google Cloud Run is to enable background processes, which basically disables the serverless function and makes it a normal running container. (Resulting in a ~3x price increase)
Additional context This problem hasn’t occurred yet, but if an eventhandler does resource intensive tasks that take longer than a few seconds, serverless environments would just kill the process.
This problem can occur with Google Cloud Run, Google Cloud Functions, AWS Lambda and probably similar products from other providers.
Is this something that needs to be implemented in Vendure, or is this a “won’t support” feature? There is no shame in not supporting function/lambda like envs, but semi-serverless/autoscaling envs like Google Cloud Run are great platforms to save costs.
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:8 (5 by maintainers)
Top GitHub Comments
Here’s a few thoughts:
It occurs to me that the eventbus and job queue essentially accomplish very similar tasks. Would it be an option to merge the two together?