azure-functions-host icon indicating copy to clipboard operation
azure-functions-host copied to clipboard

How to get and set custom status in the Isolated Worker model?

Open DeltekDavid opened this issue 1 year ago • 4 comments

Is your question related to a specific version? If so, please specify:

Functions 4.x on .NET 8.0, Isolated Worker model

What language does your question apply to? (e.g. C#, JavaScript, Java, All)

C#

Question

We're planning on migrating our .NET 6 in-process functions to .NET 8 with isolated workers. In our current code, we make extensive use of the custom status API to store things like progress percentage. The client can then poll for the latest status and update a progress bar.

For example, we have code like:

            int percentComplete = (int)((double)(itemsDone) / itemsTotal * 100);
            context.SetCustomStatus(new BackendProcessProgress
            {
                ProgressPercentage = percentComplete
            });

and

        DurableOrchestrationStatus status = await client.GetStatusAsync(instanceId);  

Is there equivalent functionality in Isolated Worker? If not, what are the best practices/recommendations for doing this sort of thing?

DeltekDavid avatar Aug 13 '24 20:08 DeltekDavid

@DeltekDavid Thanks for reporting please share all the repro steps. what you are trying

bhagyshricompany avatar Aug 19 '24 10:08 bhagyshricompany

@bhagyshricompany this isn't a bug, I just want to know how to do the equivalent things in the new Isolated Process model (and whether it's even possible). Thanks

DeltekDavid avatar Aug 19 '24 13:08 DeltekDavid

@DeltekDavid the .NET Isolated language worker extension, TaskOrchestrationContext contains a SetCustomStatus method equivalent.

With the DurableTaskClient you can get the Instance metadata and then Read the Custom Status:

var orchestrationMetadata = await client.GestInstanceAsync(instanceId);
var customStatus = orchestrationMetadata.ReadCustomStatusAs<BackendProcessProgress>();

cjaliaga avatar Aug 22 '24 15:08 cjaliaga

Thank you @cjaliaga , this looks like just the thing. I couldn't find any mention of it in the docs, though. They still refer to the in-process version.

DeltekDavid avatar Aug 22 '24 15:08 DeltekDavid

Closing as resolved.

fabiocav avatar Oct 24 '24 05:10 fabiocav