You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+21-10Lines changed: 21 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,13 +11,31 @@ Implements all [recommended best practises](https://developer.github.com/v3/guid
11
11
12
12
## Usage
13
13
14
-
The code below creates a "Hello, world!" issue on every repository in a given organization. Without the throttling plugin it would send many requests in parallel and would hit rate limits very quickly. But the `@octokit/plugin-throttling` makes sure that no requests using the same authentication token are throttled correctly.
14
+
The code below creates a "Hello, world!" issue on every repository in a given organization. Without the throttling plugin it would send many requests in parallel and would hit rate limits very quickly. But the `@octokit/plugin-throttling` slows down your requests according to the official guidelines, so you don't get blocked before your quota is exhausted.
15
+
16
+
The `throttle.onAbuseLimit` and `throttle.onRateLimit` options are required. Return `true` to automatically retry the request after `retryAfter` seconds.
15
17
16
18
```js
17
-
constOctokit=require('@ocotkit/rest')
19
+
constOctokit=require('@octokit/rest')
18
20
.plugin(require('@octokit/plugin-throttling'))
19
21
20
-
constoctokit=newOctokit()
22
+
constoctokit=newOctokit({
23
+
throttle: {
24
+
onRateLimit: (retryAfter, options) => {
25
+
console.warn(`Request quota exhausted for request ${options.method}${options.url}`)
26
+
27
+
if (options.request.retryCount===0) { // only retries once
28
+
console.log(`Retrying after ${retryAfter} seconds!`)
29
+
returntrue
30
+
}
31
+
},
32
+
onAbuseLimit: (retryAfter, options) => {
33
+
// does not retry, only logs a warning
34
+
console.warn(`Abuse detected for request ${options.method}${options.url}`)
35
+
}
36
+
}
37
+
})
38
+
21
39
octokit.authenticate({
22
40
type:'token',
23
41
token:process.env.TOKEN
@@ -35,13 +53,6 @@ async function createIssueOnAllRepos (org) {
35
53
}
36
54
```
37
55
38
-
Handle events
39
-
40
-
```js
41
-
octokit.throttle.on('rate-limit', (retryAfter) =>console.warn(`Rate-limit hit, retrying after ${retryAfter}s`))
42
-
octokit.throttle.on('abuse-limit', (retryAfter) =>console.warn(`Abuse-limit hit, retrying after ${retryAfter}s`))
0 commit comments