Skip to content

Commit 112e494

Browse files
committed
Only attempt to retry sending an extension life cycle event (install / update) once per release, when the first attempt failed.
1 parent 41ae2a0 commit 112e494

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/life-cycle/startup.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ export async function onStartUp(extensionContext: vscode.ExtensionContext) {
5050
extension: versions.extension,
5151
vscode: versions.vscode,
5252
nonce: nonce
53-
}]
53+
}],
54+
attempts: 1
5455
};
5556
} else {
5657
// Update
@@ -62,15 +63,18 @@ export async function onStartUp(extensionContext: vscode.ExtensionContext) {
6263
to: state.current,
6364
nonce: nonce
6465
});
66+
state.attempts = 1;
6567
}
6668

6769
await saveLifeCycleState(extensionContext, state);
6870
state.apiAvailable = await sendQueue(state.queue);
6971
state.queue = [];
7072
await saveLifeCycleState(extensionContext, state);
7173

72-
} else if (state.queue.length > 0) {
74+
} else if (state.queue.length > 0 && state.attempts < 2) {
7375
// There are one or more events in the queue that previously failed to send, send them
76+
state.attempts++;
77+
await saveLifeCycleState(extensionContext, state);
7478
state.apiAvailable = await sendQueue(state.queue);
7579
state.queue = [];
7680
await saveLifeCycleState(extensionContext, state);

src/life-cycle/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export interface LifeCycleState {
5252
};
5353
apiAvailable: boolean;
5454
queue: LifeCycleEvent[];
55+
attempts: number;
5556
}
5657

5758
/**
@@ -91,7 +92,7 @@ export function getLifeCycleStateInDirectory(directory: string) {
9192
resolve(null);
9293
} else {
9394
try {
94-
resolve(JSON.parse(data.toString()));
95+
resolve(Object.assign({ attempts: 1 }, JSON.parse(data.toString())));
9596
} catch (_) {
9697
resolve(null);
9798
}

0 commit comments

Comments
 (0)