-
Notifications
You must be signed in to change notification settings - Fork 29
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
Add retry option #54
Add retry option #54
Conversation
{ | ||
retries: retryOption ? MAX_RETRY_COUNT : 0, | ||
onRetry: (err, num) => { | ||
console.log(err); | ||
console.log(`Waiting for retry (${num}/${MAX_RETRY_COUNT})`); | ||
}, | ||
minTimeout: MIN_TIMEOUT_MS, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
リトライはデフォルトの設定ではOFFとしています、
Exponential Backoffのアルゴリズムについては、async-retryのReadmeに記載があります。
https://github.com/vercel/async-retry#api
こちらの設定の場合、
1回目のリトライ: 1回目のリクエスト失敗から、5秒〜10秒のディレイ
2回目のリトライ: 2回目のリクエスト失敗から、10秒〜20秒のディレイ
の間に実行されます。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
全体的に良さそうです!
1点だけ、get, createなどのメソッドを呼び出すときに上書きできる方がいいかなと思いました。
SDKの用途として、サーバー側、クライアント側の2つがありますが、このうちクライアント側はSWRなどのライブラリを使用することも多く、その場合はRetryオプションをオフにするのではないかと思いました。
そのため、デフォルトの設定をcreateClientで設定し、メソッド側でそれを上書きできるような設計はどうでしょうか?
@dc7290
クライアントサイドだと、別ライブラリでの制御としたいケースがありそうというのは、確かにですね。 |
対応ありがとうございます!すばらしい! |
レビューありがとうございました! リトライ設定のスコープをより柔軟に制限できても良さそうという件は、
という観点があるかとおもったので、こちらについては、マージしてリリースする流れで進めたいと思います。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
上記方針で良いと思います。
対応ありがとうございます!
概要
APIのレスポンスがエラーで返却された際に、最大2回までリトライを行うオプションを追加しました。
(最初のリクエストと合わせて計3回)
Issue #38 に対応するPRとなります。
提案では、リクエスト時のオプションの案もありましたが、Clientの生成時にオプション指定する形としています。
リトライにあたっては、リクエストの分散のため、
ExponentialBackoff
が採用されています。(
async-retry
ライブラリにて、標準的に実装されています。)実際の挙動
Next.jsでビルドを行った際の挙動です。
(リトライ再現の都合上、404の際にもリトライするように変更して、実施してます。)
Screen.Recording.2023-04-15.at.7.16.58.PM.mov