6. Defining long-running resource operations
If your service uses any long-running operations (LROs; see our guidelines for specifics), you will need to define a “status monitor” operation which can report the status of the operation.
Let’s say that we want to make our createOrUpdateWidget
and deleteWidget
operations long-running. Here’s how we can update our Widgets
interface to accomplish that:
- We change
createOrUpdateWidget
to useLongRunningResourceCreateOrReplace<Widget>
anddeleteWidget
to useLongRunningResourceDelete
. - We define the
getWidgetOperationStatus
operation based on theGetResourceOperationStatus
signature. This defines the operation status monitor as a child resource of theWidget
type so that it shows up under that resource in the route hierarchy. - We must add the
pollingOperation
decorator to both of the long-running operations and reference theWidgets.getWidgetOperationStatus
operation. This connects the long-running operations to their associated status monitor operation to make it easier for service clients to be generated.
NOTE: The status monitor operation must be defined earlier in the interface than the long-running operations that reference it otherwise TypeSpec will not be able to resolve the reference!
See considerations for service design for more information about LROs.