Azure / Azure/azure-functions-host
Host Level Event Support
- Dominant language
- C#
- Stars
- 2k
- Forks
- 482
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 37
Description
Consider adding the ability for user code to be triggered on various host level events, e.g. Startup/Shutdown. Here is a case from SO where the user would like to perform a flush operation on static data: https://stackoverflow.com/questions/36760241/intercept-azure-function-host-shutdown-flush-application-insights-telemetryclie. This would also provide a mechanism for users to write Function App initialization code - i.e. startup time logic that only needs to be run once in an app domain.
We could introduce a new Functions specific trigger that triggers on system events. Users can then write a function for these and handle as is - no new mechanism for running user code is needed. This is similar in spirit to the ErrorTrigger extension I wrote (sample code [here](https://github.com/Azure/azure-webjobs-sdk-extensions/blob/master/src/ExtensionsSample/Samples/ErrorMonitoringSamples.cs)). However for functions we might want to generalize that more so its not just errors. Perhaps rather than making this Functions specific, it can be a first class Extension, since the scenarios exist outside of Functions. We could allow people to write a trigger like `[HostEventTrigger("Shutdown")] HostEvent event`. This would facilitate existing scenarios as well. We could then expose this new extension in Functions.
Let's see if more scenarios pop up requiring something like this, or if there are other better ways to solve these cases. Ideally we don't really want users thinking in terms of the host - we want them to just focus on relatively short lived functions.
Contributor guide
Research direction
Start with the ErrorMonitoringSamples.cs example linked in the issue and review the shutdown-flush and one-time initialization scenarios described there. Compare the proposed HostEventTrigger("Shutdown") approach with other possible host lifecycle mechanisms. Done requires a decided, documented lifecycle API and agreement on the supported events and extension surface.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp
- Domain
- backend, cloud
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100