3

I'm building an Azure Durable Function App, it is triggered by Timer 1 time per day. For some reason, I want to persist state (e.g. A token, or an array) from previous run, is that possible?

A lot of official docs will start with Azure Durable Function is statefull, I only know that the output from one activity can be used as input of another activity. And Chris Gillum just skip that topic in youtube video

Ethan Wang
  • 85
  • 2
  • 11
  • 1
    You can use a sql db, or blob/file storage to maintain the last run state. Durable functions only store enough state to allow it to start executing when it starts after the awaiting on an activity function. Note that in general an await is still billed and the function remains "running". However await on an activity function in a durable function is special because the function stops executing, and is invoked later when the result of the activity function becomes available. This is the main scenario that durable function solves. This enables function chaining, farm out, etc. – Turbo Aug 12 '19 at 05:34

1 Answers1

4

It depends a bit how you are going to need that state. If the object is an output from one activity function and passed into another then you can use the function chaining pattern such as Sajeetharan described because the inputs for the activity function are persisted by default.

But if you want to capture the state of an object over a longer time (i.e. the last time your timer function ran) you can look into Durable Entities (still in preview at the time of writing):

Entity functions define operations for reading and updating small pieces of state, known as durable entities. Like orchestrator functions, entity functions are functions with a special trigger type, entity trigger. Unlike orchestrator functions, entity functions do not have any specific code constraints. Entity functions also manage state explicitly rather than implicitly representing state via control flow.

Chris Gillum wrote an article about it: https://medium.com/@cgillum/azure-functions-durable-entities-67db648d2f74

If you can't use this preview version or don't like concept you can still write activity functions that have input & output bindings to table- or blob storage or CosmosDB and manage the state yourself.

Marc
  • 1,798
  • 8
  • 15