예제 #1
0
파일: azure.go 프로젝트: lvjp/packer
// WithAsyncPolling will poll until the completion of an Azure long-running operation. The delay
// time between requests is taken from the HTTP Retry-After header, if present, or the passed
// delay otherwise. Polling may be canceled by signaling on the optional http.Request channel.
func WithAsyncPolling(defaultDelay time.Duration) autorest.SendDecorator {
	return func(s autorest.Sender) autorest.Sender {
		return autorest.SenderFunc(func(r *http.Request) (*http.Response, error) {
			resp, err := s.Do(r)
			for err == nil && ResponseIsLongRunning(resp) {
				err = autorest.DelayForBackoff(autorest.GetPollingDelay(resp, defaultDelay), 1, r.Cancel)
				if err == nil {
					resp, err = s.Do(r)
				}
			}
			return resp, err
		})
	}
}
예제 #2
0
func withWatcher() autorest.SendDecorator {
	return func(s autorest.Sender) autorest.Sender {
		return autorest.SenderFunc(func(r *http.Request) (*http.Response, error) {
			fmt.Printf("Sending %s %s\n", r.Method, r.URL)
			resp, err := s.Do(r)
			fmt.Printf("...received status %s\n", resp.Status)
			if autorest.ResponseRequiresPolling(resp) {
				fmt.Printf("...will poll after %d seconds\n",
					int(autorest.GetPollingDelay(resp, time.Duration(0))/time.Second))
				fmt.Printf("...will poll at %s\n", autorest.GetPollingLocation(resp))
			}
			fmt.Println("")
			return resp, err
		})
	}
}