Skip to content

Commit 3026e88

Browse files
Wait for initial sync to be complete before executing (#142)
1. Waits for initial upload to finish before executing remote code 2. Bumps up bricks cli version https://user-images.githubusercontent.com/88374338/198308478-4357856d-d64d-4f16-a1e6-f1b39229a471.mov
1 parent 2827a57 commit 3026e88

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

packages/databricks-vscode/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@
482482
"scripts": {
483483
"vscode:prepublish": "rm -rf out && yarn run package:compile && yarn run package:copy-webview-toolkit",
484484
"package": "vsce package",
485-
"package:cli:fetch": "BRICKS_VERSION=v0.0.4 && bash ./scripts/fetch-bricks-cli.sh ${BRICKS_VERSION} ${BRICKS_ARCH:-}",
485+
"package:cli:fetch": "BRICKS_VERSION=v0.0.6 && bash ./scripts/fetch-bricks-cli.sh ${BRICKS_VERSION} ${BRICKS_ARCH:-}",
486486
"package:cli:link": "rm -f ./bin/bricks && ln -s ../../../../bricks/bricks bin",
487487
"package:compile": "yarn run esbuild:base --minify",
488488
"package:copy-webview-toolkit": "cp ./node_modules/@vscode/webview-ui-toolkit/dist/toolkit.js ./out/toolkit.js",

packages/databricks-vscode/src/cli/BricksTasks.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,15 @@ describe("tests for BricksSycnParser", () => {
5656
);
5757
});
5858

59-
it("processing empty logs transitions sync status from INACTIVE -> WATCHING_FOR_CHANGES", () => {
59+
it("processing empty logs transitions sync status from STOPPED -> IN_PROGRESS and we wait for initial sync complete", () => {
6060
assert.equal(syncState, "STOPPED");
6161
bricksSycnParser.process("");
62+
assert.equal(syncState, "IN_PROGRESS");
63+
bricksSycnParser.process("[INFO] Initial Sync Complete");
6264
assert.equal(syncState, "WATCHING_FOR_CHANGES");
6365
});
6466

65-
it("processing action log transitions sync status from INACTIVE -> INPROGRESS", () => {
67+
it("processing action log transitions sync status from STOPPED -> INPROGRESS", () => {
6668
assert.equal(syncState, "STOPPED");
6769
bricksSycnParser.process("Action: PUT: hello.txt");
6870
assert.equal(syncState, "IN_PROGRESS");
@@ -72,12 +74,14 @@ describe("tests for BricksSycnParser", () => {
7274
// recieving some random logs from bricks sync
7375
assert.equal(syncState, "STOPPED");
7476
bricksSycnParser.process("some random logs");
75-
assert.equal(syncState, "WATCHING_FOR_CHANGES");
77+
assert.equal(syncState, "IN_PROGRESS");
7678

7779
// upload hello.txt
7880
bricksSycnParser.process("Action: PUT: hello.txt");
7981
assert.equal(syncState, "IN_PROGRESS");
8082
bricksSycnParser.process("Uploaded hello.txt");
83+
assert.equal(syncState, "IN_PROGRESS");
84+
bricksSycnParser.process("[INFO] Initial Sync Complete");
8185
assert.equal(syncState, "WATCHING_FOR_CHANGES");
8286

8387
// delete bye.txt

packages/databricks-vscode/src/cli/BricksTasks.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export class SyncTask extends Task {
9292
export class BricksSyncParser {
9393
private filesBeingUploaded = new Set<string>();
9494
private filesBeingDeleted = new Set<string>();
95+
private firstSyncDone = false;
9596

9697
constructor(
9798
private syncStateCallback: (state: SyncState) => void,
@@ -190,6 +191,15 @@ export class BricksSyncParser {
190191
this.filesBeingDeleted.delete(filePath);
191192
}
192193

194+
// We block on execing any commands on vscode until we get a message from
195+
// bricks cli that the initial sync is done
196+
private parseForFirstSync(line: string) {
197+
var indexOfSyncComplete = line.indexOf("Initial Sync Complete");
198+
if (indexOfSyncComplete !== -1) {
199+
this.firstSyncDone = true;
200+
}
201+
}
202+
193203
// This function processes the stderr logs from bricks sync and parses it
194204
// to compute the sync state ie determine whether the remote files match
195205
// what we have stored locally.
@@ -201,6 +211,11 @@ export class BricksSyncParser {
201211
this.parseForActionsInitiated(line);
202212
this.parseForUploadCompleted(line);
203213
this.parseForDeleteCompleted(line);
214+
215+
if (!this.firstSyncDone) {
216+
this.parseForFirstSync(line);
217+
}
218+
204219
// this.writeEmitter.fire writes to the pseudoterminal for the
205220
// bricks sync process
206221
this.writeEmitter.fire(line.trim());
@@ -216,7 +231,8 @@ export class BricksSyncParser {
216231
}
217232
if (
218233
this.filesBeingDeleted.size === 0 &&
219-
this.filesBeingUploaded.size === 0
234+
this.filesBeingUploaded.size === 0 &&
235+
this.firstSyncDone
220236
) {
221237
this.syncStateCallback("WATCHING_FOR_CHANGES");
222238
} else {

0 commit comments

Comments
 (0)