Skip to content

Commit

Permalink
Don't retry if RESOURCE_EXHAUSTED or CANCELLED error received (#124)
Browse files Browse the repository at this point in the history
* don't retry for RESOURCE_EXHAUSTED and CANCELLED codes
* add retry for Unknown code
* bump version to 1.0.2
  • Loading branch information
sgrebnov authored Jan 22, 2024
1 parent b6a74e1 commit c57c513
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,19 @@ main();

Read more about the Spice.ai Async HTTP API at [docs.spice.ai](https://docs.spice.ai/api/sql-query-api/http-api-1).

### Configuring retry policy
### Connection retry

From [version 1.0.1](https://github.com/spiceai/spice.js/releases/tag/v1.0.1) the `SpiceClient` implements connection retry mechanism (3 attempts by default).
The number of attempts can be configured via `setMaxRetries`:

SDK performs 3 retry attempts when using Apache Arrow Flight API. This could be configured as
```
const spiceClient = new SpiceClient('API_KEY');
spiceClient.setMaxRetries(5); // Setting to 0 will disable retries
```

Retries are performed for connection and system internal errors. It is the SDK user's responsibility to properly
handle other errors, for example RESOURCE_EXHAUSTED (HTTP 429).

## Documentation

Check out our [API documentation](https://docs.spice.ai/sdks/node.js-sdk) to learn more about how to use the Node.js SDK.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@spiceai/spice",
"description": "JS + TS SDK for spice.ai",
"version": "1.0.1",
"version": "1.0.2",
"engines": {
"node": ">=18.0.0"
},
Expand Down
3 changes: 1 addition & 2 deletions src/retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ function shouldRetryOperationForError(err: any): boolean {
}

return [
grpc.status.CANCELLED,
grpc.status.UNAVAILABLE,
grpc.status.DEADLINE_EXCEEDED,
grpc.status.RESOURCE_EXHAUSTED,
grpc.status.ABORTED,
grpc.status.INTERNAL,
grpc.status.UNKNOWN,
].includes(code);
}

Expand Down

0 comments on commit c57c513

Please sign in to comment.