Azure Triggered Webjob - Detecting when webjob stops -


i developing triggered webjob use timertrigger.

before webjob stops, need dispose objects don't know how trigger "webjob stop".

having noautomatictrigger function, know can use webjobsshutdownwatcher class handle when webjob stopping triggered job need help...

i had @ extensible triggers , binders azure webjobs sdk 1.1.0-alpha1.

is idea create custom trigger (stoptrigger) used webjobsshutdownwatcher class fire action before webjob stops ?

ok answer in question :

yes can use webjobsshutdownwatcher class because has register function called when cancellation token canceled, in other words when webjob stopping.

static void main() {     var cancellationtoken = new webjobsshutdownwatcher().token;     cancellationtoken.register(() =>     {         console.out.writeline("do whatever want before webjob stopped...");     });      var host = new jobhost();     // following code ensures webjob running continuously     host.runandblock(); } 

edit (based on matthew comment):

if use triggered functions, can add cancellationtoken parameter function signatures. runtime cancel token when host shutting down automatically, allowing function receive notification.

public static void queuefunction(         [queuetrigger("queuename")] string message,         textwriter log,         cancellationtoken cancellationtoken) {     ...     if(cancellationtoken.iscancellationrequested) return;     ... } 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -