From 1bbc180a57731e6b8e92e8af35c52e379773e762 Mon Sep 17 00:00:00 2001 From: worksofliam Date: Tue, 27 Aug 2024 22:02:26 -0400 Subject: [PATCH] Improvements to asking about a new job Signed-off-by: worksofliam --- src/config.ts | 12 +++++++++++- src/connection/manager.ts | 8 ++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/config.ts b/src/config.ts index 6ca444d4..ee3d406f 100644 --- a/src/config.ts +++ b/src/config.ts @@ -14,7 +14,6 @@ export let Config: ConnectionStorage; export let osDetail: IBMiDetail; export let JobManager: SQLJobManager = new SQLJobManager(); - export async function onConnectOrServerInstall(): Promise { const instance = getInstance(); @@ -87,6 +86,17 @@ export async function askAboutNewJob(startup?: boolean): Promise { const connection = instance.getConnection(); if (connection) { + + // Wait for the job manager to finish creating jobs if one is not selected + while (JobManager.getSelection() === undefined && JobManager.isCreatingJob()) { + await new Promise(resolve => setTimeout(resolve, 100)); + } + + // If a job is created or already selected, don't ask + if (JobManager.getSelection()) { + return true; + } + const options = startup ? [`Yes`, `Always`, `No`, `Never`] : [`Yes`, `No`]; const chosen = await window.showInformationMessage(`Would you like to start an SQL Job?`, ...options); diff --git a/src/connection/manager.ts b/src/connection/manager.ts index 4602b4ac..989c5015 100644 --- a/src/connection/manager.ts +++ b/src/connection/manager.ts @@ -19,6 +19,7 @@ export class SQLJobManager { private totalJobs = 0; private jobs: JobInfo[] = []; selectedJob: number = NO_SELECTED_JOB; + private creatingJobs: number = 0; constructor() { } @@ -39,6 +40,7 @@ export class SQLJobManager { })); try { + this.creatingJobs += 1; await newJob.connect(); if (osDetail) { @@ -59,10 +61,16 @@ export class SQLJobManager { this.selectedJob = this.jobs.length - 1; } catch (e: any) { throw e; + } finally { + this.creatingJobs -= 1; } } } + isCreatingJob() { + return this.creatingJobs > 0; + } + getRunningJobs() { return this.jobs.filter(info => [JobStatus.Ready, JobStatus.Busy].includes(info.job.getStatus())); }