Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.47k stars 4.8k forks source link

[QUERY] How to track status of async Compute operation #46419

Open adouvas opened 1 month ago

adouvas commented 1 month ago

Library name and version

Azure.ResourceManager

Query/Question

Using Old SDK (Microsoft.Azure.*), we retrieved the Azure-AsyncOperation value from the headers to track the status of Compute operations asynchronously (Start/stop VM), this is now a private value with new style sdk (Azure.ResourceManager) and I cannot access. I need to store this value to check the status of the operation in a different process

I am unable to use the RehydrationToken because I am unable to serialize/deserialize. I followed the serialization/deserialization code here https://github.com/Azure/azure-sdk-for-net/blob/dd1b7fceaf07a44397906d5af7d9b274e49ed1fb/sdk/core/Azure.Core/tests/RehydrationTokenTests.cs#L26-L32 but keep receiving an error when calling UpdateStatus on the recreated RehydrationToken.

How do I access the Azure-AsyncOperation value in the new style SDK or otherwise poll the operation status in a different process then where the operation is started?

Environment

No response

jsquire commented 1 month ago

Thank you for your feedback. Tagging and routing to the team member best able to assist.

archerzz commented 2 weeks ago

@adouvas You can manually check the status of a long running operation through:

// Start the operation
DeleteSecretOperation operation = await client.StartDeleteSecretAsync("SecretName");

while (operation.HasCompleted)
{
    // there could be more complex logic to control polling interval
    Thread.Sleep(TimeSpan.FromSeconds(60));

    Response statusResponse = await operation.UpdateStatusAsync();
    // optionally do something with the statusResponse
}

Or you could try the new rehydration API. See: https://github.com/Azure/azure-sdk-for-net/blob/d5acd659dd3de0e00888e6da2d1b5921331cd383/sdk/resourcemanager/Azure.ResourceManager/README.md#rehydrate-a-long-running-operation

adouvas commented 2 weeks ago

@archerzz our system is set up to poll the operation in a separate process than where the request is made, I stated above that both of these options won't work because the URL in the operation object and rehydration token are in private fields and get dropped in serialization. There should be a way to access the URL to poll the operation, seems like this answer tells me there no longer a way to access this in the new sdk, where should I file a bug?

archerzz commented 2 weeks ago

@archerzz our system is set up to poll the operation in a separate process than where the request is made, I stated above that both of these options won't work because the URL in the operation object and rehydration token are in private fields and get dropped in serialization. There should be a way to access the URL to poll the operation, seems like this answer tells me there no longer a way to access this in the new sdk, where should I file a bug?

@adouvas Do you have a chance to take look at the sample here: https://github.com/Azure/azure-sdk-for-net/blob/d5acd659dd3de0e00888e6da2d1b5921331cd383/sdk/resourcemanager/Azure.ResourceManager/README.md#rehydrate-a-long-running-operation

The sample codes demonstrate how to get the rehydration token and how to restore it:

// We get the rehydration token from the operation
var rgOpRehydrationToken = rgOp.GetRehydrationToken();
github-actions[bot] commented 1 week ago

Hi @adouvas. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

adouvas commented 6 days ago

@archerzz I tried that but I will double check again