Skip to content

Commit 9e97735

Browse files
Drop the retry/periodic code.
1 parent 8418a63 commit 9e97735

File tree

1 file changed

+2
-145
lines changed

1 file changed

+2
-145
lines changed

src/client/pythonEnvironments/base/locators/composite/cachingLocator.ts

Lines changed: 2 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import { Event } from 'vscode';
88
import '../../../../common/extensions';
9-
import { createDeferred, sleep } from '../../../../common/utils/async';
9+
import { createDeferred } from '../../../../common/utils/async';
1010
import { logWarning } from '../../../../logging';
1111
import { PythonEnvInfo } from '../../info';
1212
import { getMinimalPartialInfo } from '../../info/env';
@@ -32,37 +32,12 @@ export interface IPythonEnvsCache {
3232
flush(): Promise<void>;
3333
}
3434

35-
type CachingLocatorOptions = {
36-
refreshMinutes: number,
37-
refreshRetryMinutes: number,
38-
};
39-
40-
// Set defaults and otherwise adjust values.
41-
function normalizeCachingLocatorOptions(
42-
opts: Partial<CachingLocatorOptions>,
43-
defaults: CachingLocatorOptions = {
44-
refreshMinutes: 24 * 60, // 1 day
45-
refreshRetryMinutes: 10,
46-
},
47-
): CachingLocatorOptions {
48-
const normalized = { ...opts };
49-
if (normalized.refreshMinutes === undefined) {
50-
normalized.refreshMinutes = defaults.refreshMinutes;
51-
}
52-
if (normalized.refreshRetryMinutes === undefined) {
53-
normalized.refreshRetryMinutes = defaults.refreshRetryMinutes;
54-
}
55-
return normalized as CachingLocatorOptions;
56-
}
57-
5835
/**
5936
* A locator that stores the known environments in the given cache.
6037
*/
6138
export class CachingLocator implements ILocator {
6239
public readonly onChanged: Event<PythonEnvsChangedEvent>;
6340

64-
private readonly opts: CachingLocatorOptions;
65-
6641
private readonly watcher = new PythonEnvsWatcher();
6742

6843
private readonly initializing = createDeferred<void>();
@@ -74,22 +49,11 @@ export class CachingLocator implements ILocator {
7449
constructor(
7550
private readonly cache: IPythonEnvsCache,
7651
private readonly locator: ILocator,
77-
opts: {
78-
refreshMinutes?: number,
79-
refreshRetryMinutes?: number,
80-
} = {},
8152
) {
8253
this.onChanged = this.watcher.onChanged;
83-
this.opts = normalizeCachingLocatorOptions(opts);
8454
// eslint-disable-next-line @typescript-eslint/no-use-before-define
8555
this.looper = new BackgroundLooper({
8656
runDefault: () => this.doRefresh(),
87-
retry: {
88-
intervalms: this.opts.refreshRetryMinutes * 60 * 1000,
89-
},
90-
periodic: {
91-
intervalms: this.opts.refreshMinutes * 60 * 1000,
92-
},
9357
});
9458
}
9559

@@ -237,68 +201,9 @@ type RequestID = number;
237201
type RunFunc = () => Promise<void>;
238202
type NotifyFunc = () => void;
239203

240-
type RetryOptions = {
241-
maxRetries: number;
242-
intervalms: number;
243-
};
244-
245-
// Set defaults and otherwise adjust values.
246-
function normalizeRetryOptions(
247-
opts: Partial<RetryOptions> | undefined,
248-
defaults: RetryOptions = {
249-
maxRetries: 3,
250-
intervalms: 100,
251-
},
252-
): RetryOptions | undefined {
253-
if (opts === undefined) {
254-
return undefined;
255-
}
256-
const normalized = { ...opts };
257-
if (normalized.maxRetries === undefined) {
258-
normalized.maxRetries = defaults.maxRetries;
259-
} else if (normalized.maxRetries < 0) {
260-
// This is effectively infinity.
261-
normalized.maxRetries = Number.MAX_SAFE_INTEGER;
262-
}
263-
if (normalized.intervalms === undefined) {
264-
normalized.intervalms = defaults.intervalms;
265-
}
266-
return normalized as RetryOptions;
267-
}
268-
269-
type PeriodicOptions = {
270-
intervalms: number;
271-
initialTimestamp: number;
272-
};
273-
274-
function normalizePeriodicOptions(
275-
opts: Partial<PeriodicOptions> | undefined,
276-
defaults: PeriodicOptions = {
277-
intervalms: -1,
278-
initialTimestamp: -1,
279-
},
280-
): PeriodicOptions | undefined {
281-
if (opts === undefined) {
282-
return undefined;
283-
}
284-
const normalized = { ...opts };
285-
if (normalized.intervalms === undefined) {
286-
// "never run"
287-
normalized.intervalms = defaults.intervalms;
288-
}
289-
if (normalized.initialTimestamp === undefined && normalized.intervalms > -1) {
290-
normalized.initialTimestamp = Date.now() + normalized.intervalms;
291-
} else {
292-
normalized.initialTimestamp = defaults.initialTimestamp;
293-
}
294-
return normalized as PeriodicOptions;
295-
}
296-
297204
class BackgroundLooper {
298205
private readonly opts: {
299206
runDefault: RunFunc;
300-
retry?: RetryOptions;
301-
periodic?: PeriodicOptions;
302207
};
303208

304209
private started = false;
@@ -320,25 +225,16 @@ class BackgroundLooper {
320225

321226
private lastID: number | undefined;
322227

323-
private nextPeriod = -1;
324-
325228
constructor(
326229
opts: {
327230
runDefault?: RunFunc;
328-
retry?: Partial<RetryOptions>;
329-
periodic?: Partial<PeriodicOptions>;
330231
} = {},
331232
) {
332233
this.opts = {
333234
runDefault: opts.runDefault !== undefined
334235
? opts.runDefault
335236
: async () => { throw Error('no default operation provided'); },
336-
retry: normalizeRetryOptions(opts.retry),
337-
periodic: normalizePeriodicOptions(opts.periodic),
338237
};
339-
if (this.opts.periodic !== undefined) {
340-
this.nextPeriod = this.opts.periodic.initialTimestamp;
341-
}
342238
}
343239

344240
public start(): void {
@@ -432,12 +328,6 @@ class BackgroundLooper {
432328
this.done.promise.then(() => 0),
433329
this.waitUntilReady.promise.then(() => 1),
434330
];
435-
if (this.opts.periodic !== undefined && this.nextPeriod > -1) {
436-
const msLeft = Math.max(0, this.nextPeriod - Date.now());
437-
promises.push(
438-
sleep(msLeft).then(() => 2),
439-
);
440-
}
441331
return Promise.race(promises);
442332
};
443333

@@ -447,12 +337,6 @@ class BackgroundLooper {
447337
this.waitUntilReady = createDeferred<void>();
448338
// eslint-disable-next-line no-await-in-loop
449339
await this.flush();
450-
} else if (winner === 2) {
451-
// We reset the period before queueing to avoid any races.
452-
this.nextPeriod = Date.now() + this.opts.periodic!.intervalms;
453-
// Rather than running the request directly, we add
454-
// it to the queue. This avoids races.
455-
this.addRequest(this.opts.runDefault);
456340
} else {
457341
// This should not be reachable.
458342
throw Error(`unsupported winner ${winner}`);
@@ -477,7 +361,7 @@ class BackgroundLooper {
477361
const [run, , notify] = this.requests[reqID];
478362

479363
// eslint-disable-next-line no-await-in-loop
480-
await this.runRequest(run);
364+
await run();
481365

482366
// We leave the request until right before `notify()`
483367
// for the sake of any calls to `getLastRequest()`.
@@ -487,33 +371,6 @@ class BackgroundLooper {
487371
this.running = undefined;
488372
}
489373

490-
private async runRequest(run: RunFunc): Promise<void> {
491-
if (this.opts.retry === undefined) {
492-
// eslint-disable-next-line no-await-in-loop
493-
await run();
494-
return;
495-
}
496-
let retriesLeft = this.opts.retry.maxRetries;
497-
const retryIntervalms = this.opts.retry.intervalms;
498-
let retrying = false;
499-
do {
500-
try {
501-
// eslint-disable-next-line no-await-in-loop
502-
await run();
503-
} catch (err) {
504-
if (retriesLeft < 1) {
505-
throw err; // re-trhow
506-
}
507-
retriesLeft -= 1;
508-
logWarning(`failed while handling request (${err})`);
509-
logWarning(`retrying (${retriesLeft} attempts left)`);
510-
// eslint-disable-next-line no-await-in-loop
511-
await sleep(retryIntervalms);
512-
retrying = true;
513-
}
514-
} while (!retrying);
515-
}
516-
517374
private getNextID(): RequestID {
518375
// For nowe there is no way to queue up a request with
519376
// an ID that did not originate here. So we don't need

0 commit comments

Comments
 (0)