mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Force abort when systen is suspended
Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
This commit is contained in:
parent
3676eabc41
commit
473ecda1bd
@ -50,6 +50,16 @@ const onceSystemResume = () =>
|
|||||||
electron.powerMonitor.on("resume", handler);
|
electron.powerMonitor.on("resume", handler);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const onceSystemSuspend = () =>
|
||||||
|
new Promise(resolve => {
|
||||||
|
const handler = () => {
|
||||||
|
electron.powerMonitor.removeListener("suspend", handler);
|
||||||
|
resolve(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
electron.powerMonitor.on("suspend", handler);
|
||||||
|
});
|
||||||
|
|
||||||
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,11 +585,23 @@ export class KubeApi<T extends KubeObject> {
|
|||||||
|
|
||||||
onceSystemResume().then(() => {
|
onceSystemResume().then(() => {
|
||||||
clearTimeout(timedRetry);
|
clearTimeout(timedRetry);
|
||||||
|
logger.info(`[KUBE-API] system resumed, resume watching of ${watchUrl}...`);
|
||||||
timedRetry = setTimeout(() => {
|
timedRetry = setTimeout(() => {
|
||||||
this.watch({ ...opts, namespace, callback, watchId, retry: true });
|
this.watch({ ...opts, namespace, callback, watchId, retry: true });
|
||||||
// 3000 is a non-evident random value, we assume that after 3 seconds the system is ready
|
// 3000 is a non-evident random value, we assume that after 3 seconds the system is ready
|
||||||
// to start watching again. (Network interface/DNS is ready etc.)
|
// to start watching again. (Network interface/DNS is ready etc.)
|
||||||
}, 3000);
|
}, 3000);
|
||||||
|
}).catch((error) => {
|
||||||
|
logger.warn(`[KUBE-API] resume watching of ${watchUrl} error`, error);
|
||||||
|
});
|
||||||
|
|
||||||
|
onceSystemSuspend().then((suspended) => {
|
||||||
|
if (suspended) {
|
||||||
|
logger.info(`[KUBE-API] system suspended, abort watching ${watchUrl}...`);
|
||||||
|
abort?.();
|
||||||
|
}
|
||||||
|
}).catch((error) => {
|
||||||
|
logger.warn(`[KUBE-API] abort watching of ${watchUrl} error`, error);
|
||||||
});
|
});
|
||||||
|
|
||||||
responsePromise
|
responsePromise
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user