From 9e0a008713b1ce2a14cecd1c06c7e99cf0badf3f Mon Sep 17 00:00:00 2001 From: soridalac Date: Fri, 20 Dec 2024 08:29:32 -0800 Subject: [PATCH] feat: update mso with create/refresh/resume sandbox --- src/commands/org/create/sandbox.ts | 3 - src/commands/org/refresh/sandbox.ts | 4 -- src/commands/org/resume/sandbox.ts | 4 -- src/shared/sandboxCommandBase.ts | 98 ++++------------------------- 4 files changed, 13 insertions(+), 96 deletions(-) diff --git a/src/commands/org/create/sandbox.ts b/src/commands/org/create/sandbox.ts index 7d9ada0e..a49b2040 100644 --- a/src/commands/org/create/sandbox.ts +++ b/src/commands/org/create/sandbox.ts @@ -204,9 +204,6 @@ export default class CreateSandbox extends SandboxCommandBase 0) { - this.spinner.start(`Resume ${this.sandboxRequestData.action ?? 'Create/Refresh'}`); - } - this.debug('Calling resume with ResumeSandboxRequest: %s ', sandboxReq); try { diff --git a/src/shared/sandboxCommandBase.ts b/src/shared/sandboxCommandBase.ts index 4da431d2..a58f5bf3 100644 --- a/src/shared/sandboxCommandBase.ts +++ b/src/shared/sandboxCommandBase.ts @@ -128,11 +128,7 @@ export abstract class SandboxCommandBase extends SfCommand { lifecycle.on(SandboxEvents.EVENT_RESUME, async (results: SandboxProcessObject) => { this.latestSandboxProgressObj = results; - this.sandboxProgress.markPreviousStagesAsCompleted( - results.Status !== 'Completed' ? results.Status : 'Authenticating' - ); - mso.goto('Creating new sandbox'); - mso.updateData({ status: results.Status, id: results.Id, copyProgress: results.CopyProgress }); + if (results.Status === 'Activating') { mso.goto('Authenticating'); mso.updateData({ status: results.Status, id: results.Id, copyProgress: results.CopyProgress }); @@ -141,57 +137,17 @@ export abstract class SandboxCommandBase extends SfCommand { mso.updateData({ status: results.Status, id: results.Id, copyProgress: results.CopyProgress }); mso.stop(); } - - if (results.Status !== 'Completed' && !this.pollingTimeOut) { - setTimeout(() => { - this.pollingTimeOut = true; - mso.updateData({ status: 'Polling Timeout' }); - mso.stop(); - }, 15 * 60 * 1000); - return Promise.resolve(this.updateSandboxRequestData()); - } - return Promise.resolve(this.updateSandboxRequestData()); }); lifecycle.on(SandboxEvents.EVENT_ASYNC_RESULT, async (results?: SandboxProcessObject) => { this.latestSandboxProgressObj = results ?? this.latestSandboxProgressObj; this.updateSandboxRequestData(); + if (!options.isAsync) { - mso.goto('Authenticating'); - mso.updateData({ - status: results?.Status, - id: results?.Id, - copyProgress: results?.CopyProgress, - }); - if (results?.Status !== 'Completed' && !this.pollingTimeOut) { - setTimeout(() => { - this.pollingTimeOut = true; - mso.updateData({ status: 'Polling Timeout' }); - mso.stop(); - }, 15 * 60 * 1000); - } - // mso.stop(); + mso.stop(); } - // if (!options.isAsync) { - // if (results?.Status === 'Activating') { - // mso.goto('Authenticating'); - // mso.updateData({ - // status: results.Status, - // id: results.Id, - // copyProgress: results.CopyProgress - // }); - // } else if (results?.Status === 'Completed') { - // mso.goto('Done'); - // mso.updateData({ - // status: 'Completed', - // id: results.Id, - // copyProgress: results.CopyProgress - // }); - // mso.stop(); - // } - // mso.stop(); - // } + // things that require data on latestSandboxProgressObj if (this.latestSandboxProgressObj) { const progress = this.sandboxProgress.getSandboxProgress({ @@ -224,13 +180,13 @@ export abstract class SandboxCommandBase extends SfCommand { const currentStage = progress.status; this.updateStage(currentStage, 'inProgress'); - mso.goto('Authenticating'); + mso.goto('Creating new sandbox'); mso.updateData({ status: currentStage, id: results.sandboxProcessObj.Id, copyProgress: results.sandboxProcessObj.CopyProgress, }); - return Promise.resolve(this.updateProgress(results, options.isAsync)); + return Promise.resolve(this.updateProgress(results)); }); lifecycle.on(SandboxEvents.EVENT_AUTH, async (results: SandboxUserAuthResponse) => { @@ -242,44 +198,20 @@ export abstract class SandboxCommandBase extends SfCommand { this.latestSandboxProgressObj = results.sandboxProcessObj; this.updateSandboxRequestData(); this.sandboxProgress.markPreviousStagesAsCompleted(); - this.updateProgress(results, options.isAsync); + this.updateProgress(results); if (!options.isAsync) { + mso.stop(); + } + + if (results.sandboxProcessObj.Status === 'Authenticating') { mso.goto('Authenticating'); mso.updateData({ status: results.sandboxProcessObj.Status, id: results.sandboxProcessObj.Id, copyProgress: results.sandboxProcessObj.CopyProgress, }); - - if (results.sandboxProcessObj.Status !== 'Completed' && !this.pollingTimeOut) { - setTimeout(() => { - this.pollingTimeOut = true; - mso.updateData({ status: 'Polling Timeout' }); - mso.stop(); - }, 15 * 60 * 1000); - } - // mso.stop(); } - // if (!options.isAsync) { - // if (results.sandboxProcessObj.Status === 'Activating') { - // mso.goto('Authenticating'); - // mso.updateData({ - // status: results.sandboxProcessObj.Status, - // id: results.sandboxProcessObj.Id, - // copyProgress: results.sandboxProcessObj.CopyProgress - // }); - // } else if (results.sandboxProcessObj.Status === 'Completed') { - // mso.goto('Done'); - // mso.updateData({ - // status: 'Completed', - // id: results.sandboxProcessObj.Id, - // copyProgress: results.sandboxProcessObj.CopyProgress - // }); - // mso.stop(); - // } - // mso.stop(); - // } mso.goto('Done'); mso.updateData({ status: 'Completed', @@ -297,7 +229,7 @@ export abstract class SandboxCommandBase extends SfCommand { }); } this.removeSandboxProgressConfig(); - this.updateProgress(results, options.isAsync); + this.updateProgress(results); this.reportResults(results); }); @@ -337,8 +269,7 @@ export abstract class SandboxCommandBase extends SfCommand { } protected updateProgress( - event: StatusEvent | (Omit & { sandboxRes?: ResultEvent['sandboxRes'] }), - isAsync: boolean + event: StatusEvent | (Omit & { sandboxRes?: ResultEvent['sandboxRes'] }) ): void { const sandboxProgress = this.sandboxProgress.getSandboxProgress(event); this.sandboxUsername = (event as ResultEvent).sandboxRes?.authUserName; @@ -347,9 +278,6 @@ export abstract class SandboxCommandBase extends SfCommand { sandboxProgress, sandboxProcessObj: event.sandboxProcessObj, }; - if (!isAsync) { - this.spinner.status = this.sandboxProgress.formatProgressStatus(); - } } protected updateStage(stage: string | undefined, state: State): void {