Azure / azure-webjobs-sdk

Azure WebJobs SDK
MIT License
739 stars 358 forks source link

Safely short circuit function invocation from invocation filter #1310

Open kevbite opened 7 years ago

kevbite commented 7 years ago

I'm trying to create a IFunctionInvocationFilter but I want to be able to safely short circuit the invocation of the function from a filter and pass back a return value.

It's currently possible to short circuit it by throwing an exception within the OnExecutingAsync method of the filter but sequential filters wont be called and the exception is bubbled up.

It would be useful if within the Invocation filters to be able to set a property that allows skipping of the function execution (similar to the MVC framework)

I could throw something together and submit a PR of an example of what I mean?

kevbite commented 7 years ago

It might be useful if the result was also passed in and could be changed by the OnExecutedAsync on the filters too.

mamaso commented 7 years ago

Looks like there's some value here - asp.net action filters appear to have a similar feature short-circuiting if result is set in a filter, we should try to mirror that behavior.

https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc.Core/Filters/ActionFilterAttribute.cs#L49

mathewc commented 7 years ago

We're tracking some remaining work items for Filters in this issue https://github.com/Azure/azure-webjobs-sdk/issues/1284. For the initial set of functionality we kept things scoped to get feedback. We have it on our TODO list to look at return values from filters, and I updated the issue to also mention short circuiting so we can explore that.

I created a new tracking item here for the all up Result/Cancel feature: https://github.com/Azure/azure-webjobs-sdk/issues/1314

kevbite commented 7 years ago

That's great, I look forward to the features! Thanks

Gorthog commented 6 years ago

Can you please provide status update?

joshua-hayes commented 5 years ago

No progress on this halfway through 2019 now?