Azure / azure-functions-durable-powershell

PowerShell SDK for writing Durable Functions apps
MIT License
7 stars 3 forks source link

Still can't seem to pass complex output to activity functions #67

Open noaht8um opened 1 year ago

noaht8um commented 1 year ago

Related Issue: https://github.com/Azure/azure-functions-durable-extension/issues/1922

If I build up a ps object with sub-objects in an orchestration function and send that to an activity function, it ends up as a hashtable on the other side:

$InputData = [PSCustomObject]@{
            Data = $Data
            Documents = $Documents
            SyncDataType = $SyncDataType
        }
Invoke-DurableActivity -FunctionName 'Sync-DataWithDocuments' -Input $InputData

Maybe this is just a limitation but I want to be sure before I use workarounds. I can get it to work if I do the following:

$InputData = [PSCustomObject]@{
            Data = $Data
            Documents = $Documents
            SyncDataType = $SyncDataType
        }
Invoke-DurableActivity -FunctionName 'Sync-DataWithDocuments' -Input ($InputData | ConvertTo-Json -Depth 100)

Then in the activity function

function Sync-DataWithDocuments {
    Param($Object)
    $Object = $Object | ConvertTo-Json -Depth 100 | ConvertFrom-Json
}
davidmrdavid commented 1 year ago

Hi @noaht8um:

Thanks for reaching out. I'm aware of at least 1 serialization bug related to Activity invocations, but I think this particular case is working.

For the following orchestrator code:

param($Context)

$output = @()

$InputData = [PSCustomObject]@{
            Data = "Tokyo"
            Documents = "Seattle"
            SyncDataType = "London"
        }

$output += Invoke-DurableActivity -FunctionName 'Hello' -Input $InputData

$output

And this Activity

param($name)

Write-Host $name.GetType()
Write-Host $name.Keys
Write-Host $name.Values

"Hello $name!"

I get the following trace:

[2023-09-01T21:22:36.779Z] Executing 'Functions.Hello' (Reason='(null)', Id=53f33107-7a1a-496e-9c07-e6d57d7ce782)
[2023-09-01T21:22:36.814Z] INFORMATION: System.Collections.Hashtable
[2023-09-01T21:22:36.816Z] INFORMATION: SyncDataType Documents Data
[2023-09-01T21:22:36.818Z] INFORMATION: London Seattle Tokyo
[2023-09-01T21:22:36.823Z] Executed 'Functions.Hello' (Succeeded, Id=53f33107-7a1a-496e-9c07-e6d57d7ce782, Duration=47ms)

In the trace above, I can see the keys and values of the hashmap. Is this what you're seeing on your end as well?