0
votes

Playing with Azure WebJobs SDK, when I trigger my function with CallAsync() on JobHost instance, the TextWriter and CancellationToken instances passed into my function get disposed in a second, which makes it useless for logging and monitoring of cancellation state.

For debugging I run my code as console app. The code within Main() looks like:

_host = new JobHost();
_host.StartAsync().Wait();
_host.CallAsync(typeof(Functions).GetMethod("ProcessAggregationsAsync"));

Console.ReadKey();

Here is the function (without logic):

[NoAutomaticTrigger]
public static async void ProcessAggregationsAsync([Table("table1")] CloudTable tbl, TextWriter log, CancellationToken cancelToken)
{
    log.WriteLine("Hello");
    ...
    log.WriteLine("Hello 2"); // --> log is disposed
}

In the function ProcessAggregationsAsync() there is an infinite loop which does some logic (monitoring azure tables and processing some data) and works fine. The problem starts when I add code to check cancellation token or log some characteristics into provided log (TextWriter) they are disposed. Not immediately, it writes 2 entries into log (azure table "azure-webjobs-hosts") but then it fails.

What could be wrong? Why those objects get disposed?

1

1 Answers

0
votes

Oops, just noticed the obvious bug in the function signature - there should be Task instead of void (public static async Task ProcessAggregationsAsync(...)).

Doh. Why I hadn't seen it before I had to post this? :(