mirror of
https://github.com/lancedb/lancedb.git
synced 2026-01-08 21:02:58 +00:00
feat: make timeout configurable for vectordb node SDK (#1443)
This commit is contained in:
@@ -41,7 +41,7 @@ async function callWithMiddlewares (
|
||||
if (i > middlewares.length) {
|
||||
const headers = Object.fromEntries(req.headers.entries())
|
||||
const params = Object.fromEntries(req.params?.entries() ?? [])
|
||||
const timeout = 10000
|
||||
const timeout = opts?.timeout
|
||||
let res
|
||||
if (req.method === Method.POST) {
|
||||
res = await axios.post(
|
||||
@@ -82,6 +82,7 @@ async function callWithMiddlewares (
|
||||
|
||||
interface MiddlewareInvocationOptions {
|
||||
responseType?: ResponseType
|
||||
timeout?: number,
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,15 +124,19 @@ export class HttpLancedbClient {
|
||||
private readonly _url: string
|
||||
private readonly _apiKey: () => string
|
||||
private readonly _middlewares: HttpLancedbClientMiddleware[]
|
||||
private readonly _timeout: number | undefined
|
||||
|
||||
public constructor (
|
||||
url: string,
|
||||
apiKey: string,
|
||||
private readonly _dbName?: string
|
||||
timeout?: number,
|
||||
private readonly _dbName?: string,
|
||||
|
||||
) {
|
||||
this._url = url
|
||||
this._apiKey = () => apiKey
|
||||
this._middlewares = []
|
||||
this._timeout = timeout
|
||||
}
|
||||
|
||||
get uri (): string {
|
||||
@@ -230,7 +235,10 @@ export class HttpLancedbClient {
|
||||
|
||||
let response
|
||||
try {
|
||||
response = await callWithMiddlewares(req, this._middlewares, { responseType })
|
||||
response = await callWithMiddlewares(req, this._middlewares, {
|
||||
responseType,
|
||||
timeout: this._timeout,
|
||||
})
|
||||
|
||||
// return response
|
||||
} catch (err: any) {
|
||||
@@ -267,7 +275,7 @@ export class HttpLancedbClient {
|
||||
* Make a clone of this client
|
||||
*/
|
||||
private clone (): HttpLancedbClient {
|
||||
const clone = new HttpLancedbClient(this._url, this._apiKey(), this._dbName)
|
||||
const clone = new HttpLancedbClient(this._url, this._apiKey(), this._timeout, this._dbName)
|
||||
for (const mw of this._middlewares) {
|
||||
clone._middlewares.push(mw)
|
||||
}
|
||||
|
||||
@@ -72,6 +72,7 @@ export class RemoteConnection implements Connection {
|
||||
this._client = new HttpLancedbClient(
|
||||
server,
|
||||
opts.apiKey,
|
||||
opts.timeout,
|
||||
opts.hostOverride === undefined ? undefined : this._dbName
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user