1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fat fingers

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
This commit is contained in:
Hung-Han (Henry) Chen 2021-11-22 10:54:02 +02:00
parent 872e9dec7f
commit 5de48c4eaf
No known key found for this signature in database
GPG Key ID: 54B44603D251B788
2 changed files with 18 additions and 36 deletions

View File

@ -35,25 +35,11 @@ import type { IKubeWatchEvent } from "./kube-watch-api";
import { KubeJsonApi, KubeJsonApiData } from "./kube-json-api"; import { KubeJsonApi, KubeJsonApiData } from "./kube-json-api";
import { noop } from "../utils"; import { noop } from "../utils";
import type { RequestInit } from "node-fetch"; import type { RequestInit } from "node-fetch";
import AbortController from "abort-controller"; import { AbortController } from "node-abort-controller";
import { Agent, AgentOptions } from "https"; import { Agent, AgentOptions } from "https";
import type { Patch } from "rfc6902"; import type { Patch } from "rfc6902";
import electron from "electron"; import electron from "electron";
const onceSystemResume = () =>
new Promise(resolve => {
electron.powerMonitor.once("resume", () => {
resolve(true);
});
});
const onceSystemSuspend = () =>
new Promise(resolve => {
electron.powerMonitor.once("suspend", () => {
resolve(true);
});
});
export interface IKubeApiOptions<T extends KubeObject> { export interface IKubeApiOptions<T extends KubeObject> {
/** /**
* base api-path for listing all resources, e.g. "/api/v1/pods" * base api-path for listing all resources, e.g. "/api/v1/pods"
@ -575,27 +561,23 @@ export class KubeApi<T extends KubeObject> {
this.watchSystemStatus(); this.watchSystemStatus();
} }
onceSystemSuspend().then(async (suspended) => { electron.powerMonitor.once("suspend", () => {
if (suspended) { logger.info(`[KUBE-API] system suspended, abort watching of ${watchUrl}...`);
logger.info(`[KUBE-API] system suspended, abort watching of ${watchUrl}...`);
try { try {
abort(); abort();
} catch (error) { } catch (error) {
logger.error(`[KUBE-API] error aborting watch (${watchId})`, error); logger.error(`[KUBE-API] error aborting watch (${watchId})`, error);
}
const resumed = await onceSystemResume();
if (resumed) {
clearTimeout(timedRetry);
logger.info(`[KUBE-API] system resumed, resume watching of ${watchUrl}...`);
timedRetry = setTimeout(() => {
this.watch({ ...opts, namespace, callback, watchId, retry: true });
// 3000 is a naive value, we assume that after 3 seconds the system is ready
// to start watching again. (Network interface/DNS is ready etc.)
}, 3000);
}
} }
electron.powerMonitor.once("resume", () => {
clearTimeout(timedRetry);
logger.info(`[KUBE-API] system resumed, resume watching of ${watchUrl}...`);
timedRetry = setTimeout(() => {
this.watch({ ...opts, namespace, callback, watchId, retry: true });
// 3000 is a naive value, we assume that after 3 seconds the system is ready
// to start watching again. (Network interface/DNS is ready etc.)
}, 3000);
});
}); });
responsePromise responsePromise
@ -613,7 +595,7 @@ export class KubeApi<T extends KubeObject> {
if (this.systemSuspended) { if (this.systemSuspended) {
// don't retry if got "end", "close", "error" and system is suspended // don't retry if got "end", "close", "error" and system is suspended
// instead, wait for system resume and resume watch using onceSystemResume(); // instead, wait for system resume and resume watch using electron.powerMonitor.once;
return; return;
} }

View File

@ -30,7 +30,7 @@ import { ensureObjectSelfLink, IKubeApiQueryParams, KubeApi } from "./kube-api";
import { parseKubeApi } from "./kube-api-parse"; import { parseKubeApi } from "./kube-api-parse";
import type { KubeJsonApiData } from "./kube-json-api"; import type { KubeJsonApiData } from "./kube-json-api";
import type { RequestInit } from "node-fetch"; import type { RequestInit } from "node-fetch";
import { AbortController } from "node-abort-controller"; import AbortController from "abort-controller";
import type { Patch } from "rfc6902"; import type { Patch } from "rfc6902";
export interface KubeObjectStoreLoadingParams<K extends KubeObject> { export interface KubeObjectStoreLoadingParams<K extends KubeObject> {