mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add timeout option to KubeApi.watch (#4365)
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
105c875c84
commit
ca15919218
@ -208,6 +208,7 @@ export type KubeApiWatchOptions = {
|
||||
abortController?: AbortController
|
||||
watchId?: string;
|
||||
retry?: boolean;
|
||||
timeout?: number;
|
||||
};
|
||||
|
||||
export type KubeApiPatchType = "merge" | "json" | "strategic";
|
||||
@ -527,7 +528,7 @@ export class KubeApi<T extends KubeObject> {
|
||||
watch(opts: KubeApiWatchOptions = { namespace: "", retry: false }): () => void {
|
||||
let errorReceived = false;
|
||||
let timedRetry: NodeJS.Timeout;
|
||||
const { abortController: { abort, signal } = new AbortController(), namespace, callback = noop, retry } = opts;
|
||||
const { abortController: { abort, signal } = new AbortController(), namespace, callback = noop, retry, timeout } = opts;
|
||||
const { watchId = `${this.kind.toLowerCase()}-${this.watchId++}` } = opts;
|
||||
|
||||
signal.addEventListener("abort", () => {
|
||||
@ -535,8 +536,9 @@ export class KubeApi<T extends KubeObject> {
|
||||
clearTimeout(timedRetry);
|
||||
});
|
||||
|
||||
const requestParams = timeout ? { query: { timeoutSeconds: timeout }}: {};
|
||||
const watchUrl = this.getWatchUrl(namespace);
|
||||
const responsePromise = this.request.getResponse(watchUrl, null, { signal, timeout: 600_000 });
|
||||
const responsePromise = this.request.getResponse(watchUrl, requestParams, { signal, timeout: 600_000 });
|
||||
|
||||
logger.info(`[KUBE-API] watch (${watchId}) ${retry === true ? "retried" : "started"} ${watchUrl}`);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user