Host Level Event Support
See original GitHub issueConsider 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). 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.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:8
- Comments:6 (2 by maintainers)
Top GitHub Comments
Also interested in this functionality. I know there are entity functions, but those do not fit every use case.
If no one can detect when the lifetime of a workload ends there can be no efficient flushing.
Any update to this, 4 years and counting? Looking for node support to setup DB connections at startup, no matter which function is called first. Right now the work around to support this is quite poor.