當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Client.WaitForOperation方法代碼示例

本文整理匯總了Golang中github.com/Azure/azure-sdk-for-go/management.Client.WaitForOperation方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.WaitForOperation方法的具體用法?Golang Client.WaitForOperation怎麽用?Golang Client.WaitForOperation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/Azure/azure-sdk-for-go/management.Client的用法示例。


在下文中一共展示了Client.WaitForOperation方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Await

func Await(client management.Client, async asyncFunc) error {
	requestID, err := async()
	if err != nil {
		return err
	}
	return client.WaitForOperation(requestID, nil)
}
開發者ID:garimakhulbe,項目名稱:azure-sdk-for-go,代碼行數:7,代碼來源:integration_test.go

示例2: ExecuteAsyncOperation

// ExecuteAsyncOperation blocks until the provided asyncOperation is
// no longer in the InProgress state. Any known retryiable transient
// errors are retried and additional retry rules can be specified.
// If the operation was successful, nothing is returned, otherwise
// an error is returned.
func ExecuteAsyncOperation(client management.Client, asyncOperation func() (management.OperationID, error), extraRules ...RetryRule) error {
	if asyncOperation == nil {
		return fmt.Errorf("Parameter not specified: %s", "asyncOperation")
	}

	retryPolicy := append(newDefaultRetryPolicy(), extraRules...)

	for { // retry loop for azure errors, call continue for retryable errors

		operationId, err := asyncOperation()
		if err == nil && operationId != "" {
			log.Printf("Waiting for operation: %s", operationId)
			err = client.WaitForOperation(operationId, nil)
		}
		if err != nil {
			log.Printf("Caught error (%T) during retryable operation: %v", err, err)
			// need to remove the pointer receiver in Azure SDK to make these *'s go away
			if azureError, ok := err.(management.AzureError); ok {
				log.Printf("Error is Azure error, checking if we should retry...")
				if shouldRetry, backoff := retryPolicy.ShouldRetry(azureError); shouldRetry {
					log.Printf("Error needs to be retried, sleeping %v", backoff)
					time.Sleep(backoff)
					continue // retry asyncOperation
				}
			}
		}
		return err
	}
}
開發者ID:lopaka,項目名稱:packer-azure,代碼行數:34,代碼來源:operations.go

示例3: ExecuteAsyncOperation

// ExecuteAsyncOperation blocks until the provided asyncOperation is
// no longer in the InProgress state. Any known retryiable transient
// errors are retried and additional retry rules can be specified.
// If the operation was successful, nothing is returned, otherwise
// an error is returned.
func ExecuteAsyncOperation(client management.Client, asyncOperation func() (management.OperationID, error), extraRules ...RetryRule) error {
	if asyncOperation == nil {
		return fmt.Errorf("Parameter not specified: %s", "asyncOperation")
	}

	retryPolicy := append(newDefaultRetryPolicy(), extraRules...)

	for { // retry loop for azure errors, call continue for retryable errors

		operationId, err := asyncOperation()
		if err == nil {
			err = client.WaitForOperation(operationId, nil)
		}
		if err != nil {
			// need to remove the pointer receiver in Azure SDK to make these *'s go away
			if azureError, ok := err.(*management.AzureError); ok {
				if shouldRetry, backoff := retryPolicy.ShouldRetry(*azureError); shouldRetry {
					time.Sleep(backoff)
					continue // retry asyncOperation
				}
			}
		}
		return err
	}
}
開發者ID:HOSTINGLabs,項目名稱:packer-azure,代碼行數:30,代碼來源:operations.go

示例4: GetTestStorageAccount

func GetTestStorageAccount(t *testing.T, client management.Client) storage.StorageServiceResponse {
	t.Log("Retrieving storage account")
	sc := storage.NewClient(client)
	var sa storage.StorageServiceResponse
	ssl, err := sc.ListStorageServices()
	if err != nil {
		t.Fatal(err)
	}
	rnd := rand.New(rand.NewSource(time.Now().UnixNano()))

	if len(ssl.StorageServices) == 0 {
		t.Log("No storage accounts found, creating a new one")
		lc := location.NewClient(client)
		ll, err := lc.ListLocations()
		if err != nil {
			t.Fatal(err)
		}
		loc := ll.Locations[rnd.Intn(len(ll.Locations))].Name

		t.Logf("Location for new storage account: %s", loc)
		name := GenerateName()
		op, err := sc.CreateStorageService(storage.StorageAccountCreateParameters{
			ServiceName: name,
			Label:       base64.StdEncoding.EncodeToString([]byte(name)),
			Location:    loc,
			AccountType: storage.AccountTypeStandardLRS})
		if err != nil {
			t.Fatal(err)
		}
		if err := client.WaitForOperation(op, nil); err != nil {
			t.Fatal(err)
		}
		sa, err = sc.GetStorageService(name)
	} else {

		sa = ssl.StorageServices[rnd.Intn(len(ssl.StorageServices))]
	}

	t.Logf("Selected storage account '%s' in location '%s'",
		sa.ServiceName, sa.StorageServiceProperties.Location)

	return sa
}
開發者ID:garimakhulbe,項目名稱:azure-sdk-for-go,代碼行數:43,代碼來源:integration_test.go


注:本文中的github.com/Azure/azure-sdk-for-go/management.Client.WaitForOperation方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。