Skip to content

Commit

Permalink
Improvements to asking about a new job
Browse files Browse the repository at this point in the history
Signed-off-by: worksofliam <[email protected]>
  • Loading branch information
worksofliam committed Aug 28, 2024
1 parent f93f310 commit 1bbc180
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export let Config: ConnectionStorage;
export let osDetail: IBMiDetail;
export let JobManager: SQLJobManager = new SQLJobManager();


export async function onConnectOrServerInstall(): Promise<boolean> {
const instance = getInstance();

Expand Down Expand Up @@ -87,6 +86,17 @@ export async function askAboutNewJob(startup?: boolean): Promise<boolean> {
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);
Expand Down
8 changes: 8 additions & 0 deletions src/connection/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class SQLJobManager {
private totalJobs = 0;
private jobs: JobInfo[] = [];
selectedJob: number = NO_SELECTED_JOB;
private creatingJobs: number = 0;

constructor() { }

Expand All @@ -39,6 +40,7 @@ export class SQLJobManager {
}));

try {
this.creatingJobs += 1;
await newJob.connect();

if (osDetail) {
Expand All @@ -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()));
}
Expand Down

0 comments on commit 1bbc180

Please sign in to comment.