Search code examples
azureazure-sdk-.netazure-sdkazure-communication-services

How to track Azure Communication Services phone number purchase operation asynchronously using Azure.Communication.PhoneNumbers SDK?


I'm using the Azure.Communication.PhoneNumbers SDK version 1.1.0 for C# to purchase phone numbers in Azure Communication Services (ACS). I'm following this guide which demonstrates how to perform the purchase operation and wait for result. This approach works, but the purchase operation can take between 50 seconds to over 2 minutes to complete, which is too long to block the client (Http request).

I'd like to make this operation asynchronous, so I can start the purchase operation and then periodically check the status until it completes, allowing the client call to finish once the purchase is started.

The PurchasePhoneNumbersOperation class has a HasCompleted property, which means I could use a loop to poll the status in a background. However, it would be more efficient to periodically check the status using the SDK client instead of background loop.

I noticed that the operation object has a GetRehydrationToken() method. My understanding is that I could potentially use this token to reconstruct the PurchasePhoneNumbersOperation object later and check the status. However, I couldn't find clear documentation or examples on how to use the RehydrateAsync method, which expects an HttpPipeline.

My questions are:

  1. How can I properly use the GetRehydrationToken() and RehydrateAsync methods to check the status of the purchase operation asynchronously?
  2. Is there a better approach or recommended practice for tracking long-running operations like this in ACS?

Any guidance or examples would be greatly appreciated!

UPD: Looks like it's possible to get the status of the operation via OperationId using REST Api. But it's not supported by SDK.


Solution

  • After some investigation I have tested GetRehydrationToken() and for PurchasePhoneNumbersOperation it's not implemented and returns null. So, the only way to track operation status is to store the whole operation object in memory and call UpdateStatus() when needed.