Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,7 @@ export class ClusterListDataProvider
}
);

if (
element.stateMessage &&
!["RUNNING", "TERMINATED"].includes(element.state)
) {
if (element.stateMessage && element.state !== "RUNNING") {
children.push({
label: "State message:",
description: element.stateMessage,
Expand Down
30 changes: 28 additions & 2 deletions packages/databricks-vscode/src/cluster/ClusterManager.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,42 @@
import {cluster, Cluster} from "@databricks/databricks-sdk";
import {cluster, Cluster, Time, TimeUnits} from "@databricks/databricks-sdk";
import {CancellationToken, CancellationTokenSource, Disposable} from "vscode";

export class ClusterManager implements Disposable {
private cancellationTokenSource?: CancellationTokenSource;
private refreshTimer?: NodeJS.Timer;

constructor(readonly cluster: Cluster) {}
constructor(
readonly cluster: Cluster,
readonly onChange: (state: cluster.ClusterInfoState) => void = (
state
) => {},
readonly refreshTimeout: Time = new Time(10, TimeUnits.seconds)
) {
this.setInterval();
}

private setInterval() {
this.refreshTimer = setInterval(async () => {
await this.cluster.refresh();
this.onChange(this.cluster.state);
}, this.refreshTimeout.toMillSeconds().value);
}

private clearInterval() {
Comment thread
kartikgupta-db marked this conversation as resolved.
clearInterval(this.refreshTimer);
this.refreshTimer = undefined;
}

dispose() {
this.cancellationTokenSource?.cancel();
this.cancellationTokenSource?.dispose();
this.clearInterval();
}

async start(
onProgress: (state: cluster.ClusterInfoState) => void = (state) => {}
) {
this.clearInterval();
this.cancellationTokenSource?.cancel();
this.cancellationTokenSource = new CancellationTokenSource();

Expand All @@ -23,11 +46,13 @@ export class ClusterManager implements Disposable {
);

onProgress(this.cluster.state);
this.setInterval();
}

async stop(
onProgress: (state?: cluster.ClusterInfoState) => void = (state) => {}
) {
this.clearInterval();
this.cancellationTokenSource?.cancel();
this.cancellationTokenSource = new CancellationTokenSource();

Expand All @@ -38,5 +63,6 @@ export class ClusterManager implements Disposable {
onProgress(clusterInfo.state)
);
onProgress(this.cluster.state);
this.setInterval();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,9 @@ export class ConnectionManager {
if (this.cluster !== newCluster) {
this._clusterManager?.dispose();
this._clusterManager = newCluster
? new ClusterManager(newCluster)
? new ClusterManager(newCluster, (state) => {
this.onDidChangeClusterEmitter.fire(this.cluster);
})
: undefined;
this.onDidChangeClusterEmitter.fire(this.cluster);
}
Expand Down