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

Host Level Event Support #281

Open
mathewc opened this issue Apr 21, 2016 · 6 comments
Open

Host Level Event Support #281

mathewc opened this issue Apr 21, 2016 · 6 comments
Labels
Milestone

Comments

@mathewc
Copy link
Member

mathewc commented Apr 21, 2016

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). 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.

@davidebbo
Copy link
Contributor

Indeed, thinking in term of host feels odd in a server-less world. We could be scaling from 1 to 10 hosts/instances, and then back down.

Ideally, we want to be in a place where if something needs to be flushed, it just happens automatically as needed.

@mathewc
Copy link
Member Author

mathewc commented Apr 21, 2016

If you're doing static level caching of things for performance and only doing periodic flushes, you want the ability to quickly flush stuff if the process is going down. It will often not be possible to flush per function invocation. Now, if your background periodic flush is often enough, perhaps in practice you won't miss much, but ideally you want the chance to flush.

@christopheranderson christopheranderson added this to the Next milestone Apr 22, 2016
@CrazyTuna
Copy link

@fabiocav add a new answer on how to intercept graceful shutdown using a CancellationToken argument in a function. It works fine for me.
If I need to flush or dispose something when the job is shutting down it is enough for the moment.

@solvingj
Copy link

In addition to startup/shutdown hooks, I feel it's important to reiterate the mention of global state and advocate more first class support for it. If I should open up a dedicated feature request on this topic (separate from startup/shutdown hooks), please let me know.

@grbspltt
Copy link

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.

@quality-leftovers
Copy link

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.

  • I like the idea of [HostEventTrigger("Shutdown")]
  • Since there already is FunctionsStartup maybe we could have a FunctionShutdown (that can consume services via DI)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants