Repository navigation
feat(sandbox): add idempotent retry for sandbox creation and connection #457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
50eaa85
feat(sandbox): add idempotent retry for sandbox creation and connection
DROWNING2003 a99db90
fix(sandbox): add backoff between retries and fail on non-retryable e…
DROWNING2003 57c3a63
fix(sandbox): address review feedback
DROWNING2003 4bee359
fix(sandbox): kill sb2 in example when idempotency returns different …
DROWNING2003 88fdad0
fix(sandbox): recognize Node.js error codes in _isRetryable and keep …
DROWNING2003 7cd2a54
fix(sandbox): generate UUID v4 key, validate maxRetries, and add EAI_…
DROWNING2003 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,45 @@ | ||
| /** | ||
| * 幂等重试示例:同一幂等键连续两次 Create,验证返回同一沙箱。 | ||
| */ | ||
| const qiniu = require('../'); | ||
|
|
||
| const apiKey = process.env.QINIU_SANDBOX_API_KEY; | ||
| if (!apiKey) { | ||
| console.error('请设置 QINIU_SANDBOX_API_KEY 环境变量'); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const idempotencyKey = `sdk-example-${Math.floor(Date.now() / 1000)}`; | ||
| console.log('幂等键:', idempotencyKey); | ||
|
|
||
| const createOpts = { | ||
| templateID: 'base', | ||
| timeout: 300, | ||
| endpoint: process.env.QINIU_SANDBOX_ENDPOINT, | ||
| apiKey | ||
| }; | ||
|
|
||
| Promise.all([ | ||
| qiniu.Sandbox.create(Object.assign({}, createOpts, { idempotencyKey })), | ||
| qiniu.Sandbox.create(Object.assign({}, createOpts, { idempotencyKey })) | ||
| ]).then(([sb1, sb2]) => { | ||
| console.log('第一次创建:', sb1.sandboxId); | ||
| console.log('第二次创建:', sb2.sandboxId); | ||
|
|
||
| const sameSandbox = sb1.sandboxId === sb2.sandboxId; | ||
| if (sameSandbox) { | ||
| console.log('\n幂等重试验证通过:两次创建返回同一沙箱'); | ||
| } else { | ||
| console.log('\nWARNING: 两次创建返回不同沙箱'); | ||
| } | ||
|
|
||
| const cleanup = sameSandbox | ||
| ? sb1.kill() | ||
| : Promise.all([sb1.kill(), sb2.kill()]); | ||
| return cleanup.then(() => { | ||
| console.log('沙箱已清理'); | ||
| }); | ||
| }).catch(err => { | ||
| console.error('失败:', err.message); | ||
| process.exit(1); | ||
| }); |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.