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

Cancel Function execution from a Hook #169

Open
aaronpowell opened this issue Mar 9, 2023 · 0 comments
Open

Cancel Function execution from a Hook #169

aaronpowell opened this issue Mar 9, 2023 · 0 comments

Comments

@aaronpowell
Copy link
Contributor

As touched on in Azure/azure-functions-nodejs-worker#664 a scenario for a pre/post invocation hook, when used like middleware, would be to cancel/abort the execution of the Function, and even provide an alternative out binding.

Here's a scenario:

You have a REST API using Azure Functions to handle the user interactions. To ensure that you don't rely on the client to provide valid data you want to perform server validation based off a validation schema. As this is a REST API you can infer the object you're validating from the URL of the request, so rather than having each function perform its own validation you want a piece of middleware to do it.
If the validation passes, then you want to call to "original" Function so that data is persisted/etc. but if it fails validation you want to respond with a 400 Bad Request and provide the error messages.

Currently there is no way to say "stop execution" or "execute this Function instead" from within a hook, without overriding functionCallback property of the HookContext, but that's probably not recommended.

From a billing/usage standpoint, we should still treat the Function as "executed", even if there is an early abort provided, as you've still executed something in context of that Function invocation.

@ejizba ejizba added this to the Backlog Candidates milestone Apr 20, 2023
@ejizba ejizba transferred this issue from Azure/azure-functions-nodejs-worker Oct 11, 2023
@ejizba ejizba added the P2 label Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants