Search code examples
azureazure-functionsazure-webjobsazure-queues

How to get runtime status of queue triggered azure function?


My azure function is calculating results of certain request jobs (cca. 5s-5min) where each job has unique jobId based on the hash of the request message. Execution leads to deterministic results. So it is functionally "pure function". Therefore we are caching results of already evaluated jobs in a blob storage based on the jobId. All great so far.

Now if a request for jobId comes three scenarios are possible.

  1. Result is in the cache already => then it is served from the cache.
  2. Result is not in the cache and no function is running the evaluation => new invocation
  3. Result is not in the cache, but some function is already working on it => wait for result

We do some custom table storage based progress tracking magic to tell if function is working on given jobId or not yet.

It works somehow, up to the point of 5 x restart -> poison queue scenarios. There we are quite hopeless.

I feel like we are hacking around some of already reliably implemented feature of Azure Functions internals, because exactly the same info can be seen in the monitor page in azure portal or used to be visible in kudu webjobs monitor page.

How to reliably find out in c# if a given message (jobId) is currently being processed by some function and when it is not?


Solution

  • Azure Durable Functions provide a mechanism how to track progress of execution of smaller tasks.

    https://learn.microsoft.com/en-us/azure/azure-functions/durable-functions-overview

    Accroding to the "Pattern #3: Async HTTP APIs" the orchestrator can provide information about the function status in form like this:

      {"runtimeStatus":"Running","lastUpdatedTime":"2017-03-16T21:20:47Z", ...}
    

    This solves my problem about finding if given message is being processed.