@@ -14,6 +14,18 @@ import {CliWrapper, Command, SyncType} from "./CliWrapper";
1414import { ChildProcess , spawn , SpawnOptions } from "node:child_process" ;
1515import { SyncState } from "../sync/CodeSynchronizer" ;
1616import { BricksSyncParser } from "./BricksSyncParser" ;
17+ import { withLogContext } from "@databricks/databricks-sdk/dist/logging" ;
18+ import { Loggers } from "../logger" ;
19+ import { Context , context } from "@databricks/databricks-sdk/dist/context" ;
20+
21+ enum TaskSyncType {
22+ syncFull = "sync-full" ,
23+ sync = "sync" ,
24+ }
25+ const cliToTaskSyncType = new Map < SyncType , TaskSyncType > ( [
26+ [ "full" , TaskSyncType . syncFull ] ,
27+ [ "incremental" , TaskSyncType . sync ] ,
28+ ] ) ;
1729
1830export class SyncTask extends Task {
1931 constructor (
@@ -25,10 +37,10 @@ export class SyncTask extends Task {
2537 super (
2638 {
2739 type : "databricks" ,
28- task : syncType === "full" ? "sync-full" : "sync" ,
40+ task : cliToTaskSyncType . get ( syncType ) ?? "sync" ,
2941 } ,
3042 TaskScope . Workspace ,
31- syncType === "full" ? "sync-full" : "sync" ,
43+ cliToTaskSyncType . get ( syncType ) ?? "sync" ,
3244 "databricks" ,
3345 new CustomExecution ( async ( ) : Promise < Pseudoterminal > => {
3446 return new LazyCustomSyncTerminal (
@@ -49,14 +61,15 @@ export class SyncTask extends Task {
4961 }
5062
5163 static killAll ( ) {
52- let found = false ;
5364 window . terminals . forEach ( ( terminal ) => {
54- if ( terminal . name === "sync" ) {
55- found = true ;
65+ if (
66+ Object . values ( TaskSyncType )
67+ . map ( ( e ) => e as string )
68+ . includes ( terminal . name )
69+ ) {
5670 terminal . dispose ( ) ;
5771 }
5872 } ) ;
59- return found ;
6073 }
6174}
6275
@@ -168,41 +181,55 @@ export class LazyCustomSyncTerminal extends CustomSyncTerminal {
168181 ) {
169182 super ( "" , [ ] , { } , syncStateCallback ) ;
170183
184+ const ctx : Context = new Context ( {
185+ rootClassName : "LazyCustomSyncTerminal" ,
186+ rootFnName : "constructor" ,
187+ } ) ;
188+
171189 // hacky way to override properties with getters
172190 Object . defineProperties ( this , {
173191 cmd : {
174192 get : ( ) => {
175- return this . getSyncCommand ( ) . command ;
193+ return this . getSyncCommand ( ctx ) . command ;
176194 } ,
177195 } ,
178196 args : {
179197 get : ( ) => {
180- return this . getSyncCommand ( ) . args ;
198+ return this . getSyncCommand ( ctx ) . args ;
181199 } ,
182200 } ,
183201 options : {
184202 get : ( ) => {
185- return this . getProcessOptions ( ) ;
203+ return this . getProcessOptions ( ctx ) ;
186204 } ,
187205 } ,
188206 } ) ;
189207 }
190208
191- getProcessOptions ( ) : SpawnOptions {
209+ @withLogContext ( Loggers . Extension )
210+ showErrorAndKillThis ( msg : string , @context ctx ?: Context ) {
211+ ctx ?. logger ?. error ( msg ) ;
212+ window . showErrorMessage ( msg ) ;
213+ SyncTask . killAll ( ) ;
214+ return new Error ( msg ) ;
215+ }
216+
217+ @withLogContext ( Loggers . Extension )
218+ getProcessOptions ( @context ctx ?: Context ) : SpawnOptions {
192219 const workspacePath =
193220 this . connection . syncDestination ?. vscodeWorkspacePath . fsPath ;
194221 if ( ! workspacePath ) {
195- window . showErrorMessage ( "Can't start sync: No workspace opened!" ) ;
196- throw new Error ( "Can't start sync: No workspace opened!" ) ;
222+ throw this . showErrorAndKillThis (
223+ "Can't start sync: No workspace opened!" ,
224+ ctx
225+ ) ;
197226 }
198227
199228 const dbWorkspace = this . connection . databricksWorkspace ;
200229 if ( ! dbWorkspace ) {
201- window . showErrorMessage (
202- "Can't start sync: Databricks connection not configured!"
203- ) ;
204- throw new Error (
205- "Can't start sync: Databricks connection not configured!"
230+ throw this . showErrorAndKillThis (
231+ "Can't start sync: Databricks connection not configured!" ,
232+ ctx
206233 ) ;
207234 }
208235
@@ -212,35 +239,25 @@ export class LazyCustomSyncTerminal extends CustomSyncTerminal {
212239 /* eslint-disable @typescript-eslint/naming-convention */
213240 BRICKS_ROOT : workspacePath ,
214241 DATABRICKS_CONFIG_PROFILE : dbWorkspace . profile ,
242+ DATABRICKS_CONFIG_FILE : process . env . DATABRICKS_CONFIG_FILE ,
215243 HOME : process . env . HOME ,
216244 PATH : process . env . PATH ,
217245 /* eslint-enable @typescript-eslint/naming-convention */
218246 } ,
219247 } as SpawnOptions ;
220248 }
221249
222- getSyncCommand ( ) : Command {
223- if (
224- this . connection . state !== "CONNECTED" &&
225- ( SyncTask . killAll ( ) || this . killThis )
226- ) {
227- this . killThis = true ;
228- return {
229- args : [ ] ,
230- command : "" ,
231- } ;
232- }
250+ @withLogContext ( Loggers . Extension )
251+ getSyncCommand ( @context ctx ?: Context ) : Command {
233252 if ( this . command ) {
234253 return this . command ;
235254 }
236255 const syncDestination = this . connection . syncDestination ;
237256
238257 if ( ! syncDestination ) {
239- window . showErrorMessage (
240- "Can't start sync: Databricks synchronization destination not configured!"
241- ) ;
242- throw new Error (
243- "Can't start sync: Databricks synchronization destination not configured!"
258+ throw this . showErrorAndKillThis (
259+ "Can't start sync: Databricks synchronization destination not configured!" ,
260+ ctx
244261 ) ;
245262 }
246263
0 commit comments