-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix dep package manager & update docs (#6)
* add entry for dep * update docs
- Loading branch information
1 parent
175ad0c
commit ec07769
Showing
8 changed files
with
176 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* | ||
Package sdk is a toolkit for developer to create custom infrastructure via ucloud open api. | ||
*/ | ||
package sdk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Retry Policy | ||
|
||
## How to enable retrying | ||
|
||
Retrying feature is disabled by default. | ||
|
||
hen retrying is enabled, such as client-level max retries is greater than 0 (enable retrying for all request), eg. | ||
|
||
```go | ||
cfg.MaxRetries = 3 | ||
``` | ||
|
||
or request-level max retries is greater than 0 (enable retrying for current request), eg. | ||
|
||
```go | ||
req.WithRetry(3) | ||
``` | ||
|
||
## Retrying and side-effect | ||
|
||
SDK has default retry policy to prevent retrying with side-effect. It will prevent most of action when follow term: ``create``, ``allocate``, ``clone``, ``copy`` is contained. | ||
|
||
this actions will be set request-level retryable is false as default, | ||
|
||
```go | ||
req.SetRetryable(false) | ||
``` | ||
|
||
you can set it to true to re-enable it simply. | ||
|
||
``` | ||
req.SetRetryable(true) | ||
``` | ||
|
||
Here is a table to show which action will prevent retrying by default: | ||
|
||
| Action | Is Prevented | | ||
| ----------------------- | ------------ | | ||
| CreateUHostInstance | √ | | ||
| CopyCustomImage | √ | | ||
| CreateCustomImage | √ | | ||
| AllocateEIP | √ | | ||
| AllocateVIP | √ | | ||
| CreateBandwidthPackage | √ | | ||
| AllocateShareBandwidth | √ | | ||
| CreateFirewall | √ | | ||
| CreateULB | √ | | ||
| CreateVServer | √ | | ||
| CreatePolicy | √ | | ||
| CreateSSL | √ | | ||
| CreateVPC | √ | | ||
| AddVPCNetwork | √ | | ||
| CreateSubnet | √ | | ||
| CreateVPCIntercom | √ | | ||
| CreateRouteTable | √ | | ||
| CloneRouteTable | √ | | ||
| CreateUDisk | √ | | ||
| CloneUDisk | √ | | ||
| CreateProject | √ | | ||
| CreateGlobalSSHInstance | √ | | ||
| | | | ||
|
||
## Example | ||
|
||
You can see also [retry example](../examples/retry) for a full example. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# State Waiter | ||
|
||
SDK also provide state waiter helper to improver usage experience. | ||
|
||
## Why use it? | ||
|
||
Waiter can wait for remote state is achieved to target state. such as, | ||
|
||
- create and wait for resource state is completed. | ||
- invoke/start/stop a resource and wait for it is finished. | ||
- custom retry policies and wait for retrying is finished. | ||
|
||
## Usage | ||
|
||
By the default, waiter will use exponential back-off delay between twice request. you can see [advanced options](#Advanced Options) for detail. | ||
|
||
```go | ||
waiter.StateWaiter{ | ||
Pending: []string{"pending"}, | ||
Target: []string{"avaliable"}, | ||
Refresh: CustomRefreshFn, | ||
Timeout: 5 * time.Minute, | ||
} | ||
``` | ||
|
||
You can custom you own state machine from your own function. custom state refresh function should matched ``waiter.RefreshFunc``: | ||
|
||
```go | ||
type RefreshFunc func() (result interface{}, state string, err error) | ||
``` | ||
|
||
seems like: | ||
|
||
```go | ||
func CustomRefreshFn() (interface{}, string, error) { | ||
inst, err := describeUHostByID(uhostID) | ||
if err != nil { | ||
return nil, "", err | ||
} | ||
|
||
if inst == nil || inst.State != "Running" { | ||
return nil, "pending", nil | ||
} | ||
|
||
return inst, "avaliable", nil | ||
} | ||
``` | ||
|
||
## Advanced Options | ||
|
||
### Timeout | ||
|
||
Timeout option will wait and refresh until target state or timeout is reached. State waiter use exponential back-off interval. | ||
|
||
Option ``Timeout`` is required. By the default, max interval is 10s, if no other options is set, the refresh interval is: | ||
|
||
``` | ||
0 100ms 200ms 400ms 800ms 1.6s 3.2s 6.4s 10s 10s | ||
``` | ||
|
||
if ``MinTimeout`` is set, the refresh interval will start by a minimal value: | ||
|
||
``` | ||
0 3s 6s 10s 10s ... (100ms < MinTimeout <= 10s, eg. 3s) | ||
0 11s 10s 10s 10s ... (10s < MinTimeout, eg. 11s) | ||
``` | ||
|
||
if ``PollInterval`` is set, the exponential back-off interval will be disabled. it will use simple poll interval instead. | ||
|
||
``` | ||
0 3s 3s 3s 3s ... (PollInterval, eg. 3s) | ||
``` | ||
|
||
### Delay | ||
|
||
Delay option will wait until delay time is passed before first state is refreshed. | ||
|
||
```go | ||
waiter.StateWaiter{ | ||
Pending: []string{"pending"}, | ||
Target: []string{"avaliable"}, | ||
Refresh: CustomRefreshFn, | ||
Timeout: 5 * time.Minute, | ||
Delay: 30 * time.Second, | ||
} | ||
``` | ||
|
||
It is usually used in wait a little second after resource is created. | ||
|
||
## Example | ||
|
||
You can see also [wait for remote state example](../examples/wait) for a full example. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# UCloud SDK Wait Example | ||
# UCloud SDK Wait For Remote State Example | ||
|
||
## What is the goal | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters