0

I have a data pipeline that is reading the change feed from CosmosDB and loading the data into an external resource via Durable Functions. My start function (in Python) looks something like this:

import azure.durable_functions as df
import azure.functions as func


async def main(documents: func.DocumentList, starter: str):
    client = df.DurableOrchestrationClient(starter)
    instance_id = await client.start_new('MyDFOrchestrator', client_input=documents)
    logging.info(f"Started orchestration ID {instance_id}")

However, this runs into an error because the cosmosDBTrigger passes in a list of Cosmos Documents but client.start_new() needs a JSON-serializable input value. I can get around this by shoving the list into a simple JSON object (like {"doc_list": [{doc1}, {doc2}, {doc3}]}) but I want to make sure I'm not missing something in the API to handle this pattern.

juunas
  • 54,244
  • 13
  • 113
  • 149
Comrade_Question
  • 305
  • 1
  • 2
  • 10

1 Answers1

1

It should be fine to pass JSON as input value to the orchestrator. There is an example here which does similar. Though the example is with http trigger, but the concerned area here has nothing to do what trigger you use at the starter/triggering Function.

Alternatively, you can create a concrete serializable class holding the model/entity structure (much cleaner than raw json). To create serializable classes, all we require is for your class to export two static methods: to_json() and from_json(). The Durable Functions framework will interally call these classes to serialize and de-serialize your custom class. Therefore, you should design these two functions such that calling from_json on the result of to_json is able to reconstruct your class.

krishg
  • 5,935
  • 2
  • 12
  • 19