From b81a7c8872308965d5e5b2dd6f4c5750246efbdc Mon Sep 17 00:00:00 2001 From: soridalac Date: Fri, 13 Dec 2024 09:27:10 -0800 Subject: [PATCH 1/9] feat: update mso --- src/commands/org/create/sandbox.ts | 49 ++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/src/commands/org/create/sandbox.ts b/src/commands/org/create/sandbox.ts index daa6dd29..15647473 100644 --- a/src/commands/org/create/sandbox.ts +++ b/src/commands/org/create/sandbox.ts @@ -6,12 +6,14 @@ */ import { Duration } from '@salesforce/kit'; +import { MultiStageOutput } from '@oclif/multi-stage-output'; import { Flags } from '@salesforce/sf-plugins-core'; -import { Lifecycle, Messages, SandboxEvents, SandboxRequest, SfError } from '@salesforce/core'; +import { Lifecycle, Messages, SandboxEvents, SandboxProcessObject, SandboxRequest, SfError } from '@salesforce/core'; import { Interfaces } from '@oclif/core'; import requestFunctions, { readSandboxDefFile } from '../../../shared/sandboxRequest.js'; import { SandboxCommandBase, SandboxCommandResponse } from '../../../shared/sandboxCommandBase.js'; import { SandboxLicenseType } from '../../../shared/orgTypes.js'; +import sandboxRequest from '../../../shared/sandboxRequest.js'; Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); const messages = Messages.loadMessages('@salesforce/plugin-org', 'create.sandbox'); @@ -124,6 +126,7 @@ export default class CreateSandbox extends SandboxCommandBase({ + stages: this.flags.async + ? ['Prepare request', 'Send request', 'Done'] + : ['Prepare request', 'Send request', 'Waiting for org to respond', 'Done'], + title: this.flags.async ? 'Create Sandbox (async)': 'Create Sandbox', + jsonEnabled: false, + postStagesBlock: [ + { + label: 'SandboxId', + get: (data) => data?.id, + type: 'dynamic-key-value', + bold: true + }, + { + label: 'Status', + get: (data) => data?.status, + type: 'dynamic-key-value', + bold: true + }, + ] + }); + + mso.goto('Prepare request', {status: 'Pending'}); + if (!this.flags.async) { - this.spinner.start('Sandbox Create'); + mso.skipTo('Send request'); } this.debug('Calling create with SandboxRequest: %s ', sandboxReq); try { + mso.goto('Send request', {status: 'In Progress'}); const sandboxProcessObject = await this.prodOrg.createSandbox(sandboxReq, { wait: this.flags.wait, interval: this.flags['poll-interval'], async: this.flags.async, }); + console.log('Sandbox Process Object', sandboxProcessObject); + + mso.updateData({status: sandboxProcessObject.Status, id: sandboxProcessObject.Id}); + + if (sandboxProcessObject.Status === 'In Progress') { + mso.goto('Waiting for org to respond', { status: 'In Progress', id: sandboxProcessObject.Id}); + } + this.latestSandboxProgressObj = sandboxProcessObject; this.saveSandboxProgressConfig(); + + mso.goto('Done', {status: sandboxProcessObject.Status, id: sandboxProcessObject.Id}); if (this.flags.async) { + mso.goto('Waiting for org to respond', { status: 'Pending', id: sandboxProcessObject.Id}); + + mso.skipTo('Done', {status: sandboxProcessObject.Status, id: sandboxProcessObject.Id}); + mso.stop(); process.exitCode = 68; } return this.getSandboxCommandResponse(); } catch (err) { - this.spinner.stop(); + mso.error() + mso.stop(); if (this.pollingTimeOut && this.latestSandboxProgressObj) { void lifecycle.emit(SandboxEvents.EVENT_ASYNC_RESULT, undefined); process.exitCode = 68; From 4ce625468e378e633cea481b5c960052aa843839 Mon Sep 17 00:00:00 2001 From: soridalac Date: Fri, 13 Dec 2024 09:29:20 -0800 Subject: [PATCH 2/9] feat: update mso --- src/commands/org/create/sandbox.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/org/create/sandbox.ts b/src/commands/org/create/sandbox.ts index 15647473..ec35c3a0 100644 --- a/src/commands/org/create/sandbox.ts +++ b/src/commands/org/create/sandbox.ts @@ -243,7 +243,7 @@ export default class CreateSandbox extends SandboxCommandBase Date: Mon, 16 Dec 2024 09:19:53 -0800 Subject: [PATCH 3/9] fix: mso for sandbox --- src/commands/org/create/sandbox.ts | 44 ++++++++++++++---------------- src/shared/sandboxCommandBase.ts | 21 +++++++++++++- 2 files changed, 41 insertions(+), 24 deletions(-) diff --git a/src/commands/org/create/sandbox.ts b/src/commands/org/create/sandbox.ts index ec35c3a0..2a98adac 100644 --- a/src/commands/org/create/sandbox.ts +++ b/src/commands/org/create/sandbox.ts @@ -8,12 +8,11 @@ import { Duration } from '@salesforce/kit'; import { MultiStageOutput } from '@oclif/multi-stage-output'; import { Flags } from '@salesforce/sf-plugins-core'; -import { Lifecycle, Messages, SandboxEvents, SandboxProcessObject, SandboxRequest, SfError } from '@salesforce/core'; +import { Lifecycle, Messages, SandboxEvents, SandboxRequest, SfError } from '@salesforce/core'; import { Interfaces } from '@oclif/core'; import requestFunctions, { readSandboxDefFile } from '../../../shared/sandboxRequest.js'; import { SandboxCommandBase, SandboxCommandResponse } from '../../../shared/sandboxCommandBase.js'; import { SandboxLicenseType } from '../../../shared/orgTypes.js'; -import sandboxRequest from '../../../shared/sandboxRequest.js'; Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); const messages = Messages.loadMessages('@salesforce/plugin-org', 'create.sandbox'); @@ -126,7 +125,7 @@ export default class CreateSandbox extends SandboxCommandBase({ - stages: this.flags.async - ? ['Prepare request', 'Send request', 'Done'] - : ['Prepare request', 'Send request', 'Waiting for org to respond', 'Done'], - title: this.flags.async ? 'Create Sandbox (async)': 'Create Sandbox', + const mso = new MultiStageOutput<{ status: string; id: string }>({ + stages: this.flags.async + ? ['Prepare request', 'Send request', 'Done'] + : ['Prepare request', 'Send request', 'Waiting for org to respond', 'Done'], + title: this.flags.async ? 'Create Sandbox (async)' : 'Create Sandbox', jsonEnabled: false, postStagesBlock: [ { label: 'SandboxId', get: (data) => data?.id, type: 'dynamic-key-value', - bold: true + bold: true, }, { label: 'Status', get: (data) => data?.status, type: 'dynamic-key-value', - bold: true + bold: true, }, - ] + ], }); - mso.goto('Prepare request', {status: 'Pending'}); + mso.goto('Prepare request', { status: 'Pending' }); if (!this.flags.async) { - mso.skipTo('Send request'); + mso.skipTo('Sandbox Create', { status: 'Pending' }); } this.debug('Calling create with SandboxRequest: %s ', sandboxReq); try { - mso.goto('Send request', {status: 'In Progress'}); + mso.goto('Send request', { status: 'In Progress' }); const sandboxProcessObject = await this.prodOrg.createSandbox(sandboxReq, { wait: this.flags.wait, interval: this.flags['poll-interval'], @@ -245,27 +244,26 @@ export default class CreateSandbox extends SandboxCommandBase extends SfCommand { ): void { lifecycle.on('POLLING_TIME_OUT', async () => { this.pollingTimeOut = true; + this.warn('Sandbox creation process time out.'); + + if (this.latestSandboxProgressObj) { + const sandboxId = this.latestSandboxProgressObj.Id; + if (sandboxId) { + this.info(`Sandbox ID: ${sandboxId}`); + } + } return Promise.resolve(this.updateSandboxRequestData()); }); @@ -131,6 +139,12 @@ export abstract class SandboxCommandBase extends SfCommand { lifecycle.on(SandboxEvents.EVENT_STATUS, async (results: StatusEvent) => { this.latestSandboxProgressObj = results.sandboxProcessObj; + const sandboxId = this.latestSandboxProgressObj?.Id; + + if (sandboxId) { + this.info(`Sandbox ID: ${sandboxId}`); + } + this.updateSandboxRequestData(); const progress = this.sandboxProgress.getSandboxProgress(results); const currentStage = progress.status; @@ -144,7 +158,12 @@ export abstract class SandboxCommandBase extends SfCommand { }); lifecycle.on(SandboxEvents.EVENT_RESULT, async (results: ResultEvent) => { - this.latestSandboxProgressObj = results.sandboxProcessObj; + // this.latestSandboxProgressObj = results.sandboxProcessObj; + const sandboxId = results.sandboxProcessObj?.Id; + + if (sandboxId) { + this.info(`Sandbox created with ID: ${sandboxId}`); + } this.updateSandboxRequestData(); this.sandboxProgress.markPreviousStagesAsCompleted(); this.updateProgress(results, options.isAsync); From 1732d412a47b9bf49f9dc4c1190493503eb713af Mon Sep 17 00:00:00 2001 From: soridalac Date: Mon, 16 Dec 2024 12:00:58 -0800 Subject: [PATCH 4/9] fix: mso --- src/commands/org/create/sandbox.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/commands/org/create/sandbox.ts b/src/commands/org/create/sandbox.ts index 2a98adac..217a7e25 100644 --- a/src/commands/org/create/sandbox.ts +++ b/src/commands/org/create/sandbox.ts @@ -213,7 +213,7 @@ export default class CreateSandbox extends SandboxCommandBase data?.id, type: 'dynamic-key-value', bold: true, @@ -246,18 +246,13 @@ export default class CreateSandbox extends SandboxCommandBase Date: Tue, 17 Dec 2024 10:21:21 -0800 Subject: [PATCH 5/9] fix: mso --- src/commands/org/create/sandbox.ts | 76 +++++++++++++++--------------- src/shared/sandboxCommandBase.ts | 73 ++++++++++++++++++++++------ 2 files changed, 97 insertions(+), 52 deletions(-) diff --git a/src/commands/org/create/sandbox.ts b/src/commands/org/create/sandbox.ts index 217a7e25..dad5d0de 100644 --- a/src/commands/org/create/sandbox.ts +++ b/src/commands/org/create/sandbox.ts @@ -6,7 +6,6 @@ */ import { Duration } from '@salesforce/kit'; -import { MultiStageOutput } from '@oclif/multi-stage-output'; import { Flags } from '@salesforce/sf-plugins-core'; import { Lifecycle, Messages, SandboxEvents, SandboxRequest, SfError } from '@salesforce/core'; import { Interfaces } from '@oclif/core'; @@ -192,51 +191,52 @@ export default class CreateSandbox extends SandboxCommandBase({ - stages: this.flags.async - ? ['Prepare request', 'Send request', 'Done'] - : ['Prepare request', 'Send request', 'Waiting for org to respond', 'Done'], - title: this.flags.async ? 'Create Sandbox (async)' : 'Create Sandbox', - jsonEnabled: false, - postStagesBlock: [ - { - label: 'Sandbox ID', - get: (data) => data?.id, - type: 'dynamic-key-value', - bold: true, - }, - { - label: 'Status', - get: (data) => data?.status, - type: 'dynamic-key-value', - bold: true, - }, - ], + this.registerLifecycleListeners(lifecycle, { + isAsync: this.flags.async, + setDefault: this.flags['set-default'], + alias: this.flags.alias, + prodOrg: this.prodOrg, + tracksSource: this.flags['no-track-source'] === true ? false : undefined, }); - - mso.goto('Prepare request', { status: 'Pending' }); + // const mso = new MultiStageOutput<{ status: string; id: string }>({ + // stages: this.flags.async + // ? ['Prepare request', 'Send request', 'Done'] + // : ['Prepare request', 'Send request', 'Waiting for org to respond', 'Done'], + // title: this.flags.async ? 'Create Sandbox (async)' : 'Create Sandbox', + // jsonEnabled: false, + // postStagesBlock: [ + // { + // label: 'Sandbox ID', + // get: (data) => data?.id, + // type: 'dynamic-key-value', + // bold: true, + // }, + // { + // label: 'Status', + // get: (data) => data?.status, + // type: 'dynamic-key-value', + // bold: true, + // }, + // ], + // }); + + // this.mso.goto('Prepare request', { status: 'Pending' }); if (!this.flags.async) { - mso.skipTo('Sandbox Create', { status: 'Pending' }); + this.spinner.start('Sandbox Create'); + // this.mso.skipTo('Sandbox Create', { status: 'Pending' }); } this.debug('Calling create with SandboxRequest: %s ', sandboxReq); try { - mso.goto('Send request', { status: 'In Progress' }); + // this.mso.goto('Send request', { status: 'In Progress' }); const sandboxProcessObject = await this.prodOrg.createSandbox(sandboxReq, { wait: this.flags.wait, interval: this.flags['poll-interval'], @@ -244,21 +244,21 @@ export default class CreateSandbox extends SandboxCommandBase extends SfCommand { : this.constructor.name === 'CreateSandbox' ? 'Create' : 'Create/Refresh'; + this.sandboxProgress = new SandboxProgress({ action: this.action }); } protected async getSandboxRequestConfig(): Promise { @@ -89,6 +96,34 @@ export abstract class SandboxCommandBase extends SfCommand { lifecycle: Lifecycle, options: { isAsync: boolean; alias?: string; setDefault?: boolean; prodOrg?: Org; tracksSource?: boolean } ): void { + const mso = new MultiStageOutput({ + stages: ['Creating new sandbox', 'Authenticating'], + title: 'Create Sandbox', + jsonEnabled: false, + postStagesBlock: [ + { + label: 'Sandbox ID', + get: (data): string | undefined => data?.id, + type: 'dynamic-key-value', + bold: true, + }, + { + label: 'Status', + get: (data): string | undefined => data?.status, + type: 'dynamic-key-value', + bold: true, + }, + { + label: 'Copy Progress', + get: (data): string | undefined => { + if (data?.sandboxStatus.sandboxProcessObj.CopyProgress) + return `${data?.sandboxStatus.sandboxProcessObj.CopyProgress}`; + }, + type: 'dynamic-key-value', + bold: true, + }, + ], + }); lifecycle.on('POLLING_TIME_OUT', async () => { this.pollingTimeOut = true; this.warn('Sandbox creation process time out.'); @@ -97,6 +132,7 @@ export abstract class SandboxCommandBase extends SfCommand { const sandboxId = this.latestSandboxProgressObj.Id; if (sandboxId) { this.info(`Sandbox ID: ${sandboxId}`); + mso.updateData({ status: this.latestSandboxProgressObj.Status }); } } return Promise.resolve(this.updateSandboxRequestData()); @@ -114,7 +150,7 @@ export abstract class SandboxCommandBase extends SfCommand { this.latestSandboxProgressObj = results ?? this.latestSandboxProgressObj; this.updateSandboxRequestData(); if (!options.isAsync) { - this.spinner.stop(); + // this.spinner.stop(); } // things that require data on latestSandboxProgressObj if (this.latestSandboxProgressObj) { @@ -124,7 +160,7 @@ export abstract class SandboxCommandBase extends SfCommand { }); const currentStage = progress.status; this.sandboxProgress.markPreviousStagesAsCompleted(currentStage); - this.updateStage(currentStage, 'inProgress'); + // this.updateStage(currentStage, 'inProgress'); this.updateProgress( { sandboxProcessObj: this.latestSandboxProgressObj, sandboxRes: undefined }, options.isAsync @@ -140,15 +176,15 @@ export abstract class SandboxCommandBase extends SfCommand { lifecycle.on(SandboxEvents.EVENT_STATUS, async (results: StatusEvent) => { this.latestSandboxProgressObj = results.sandboxProcessObj; const sandboxId = this.latestSandboxProgressObj?.Id; - + // results.sandboxProcessObj.Status; if (sandboxId) { this.info(`Sandbox ID: ${sandboxId}`); } this.updateSandboxRequestData(); - const progress = this.sandboxProgress.getSandboxProgress(results); - const currentStage = progress.status; - this.updateStage(currentStage, 'inProgress'); + // const progress = this.sandboxProgress.getSandboxProgress(results); + // const currentStage = progress.status; + // this.updateStage(currentStage, 'inProgress'); return Promise.resolve(this.updateProgress(results, options.isAsync)); }); @@ -231,16 +267,25 @@ export abstract class SandboxCommandBase extends SfCommand { sandboxProcessObj: event.sandboxProcessObj, }; if (!isAsync) { - this.spinner.status = this.sandboxProgress.formatProgressStatus(); + // this.spinner.status = this.sandboxProgress.formatProgressStatus(); } - } - protected updateStage(stage: string | undefined, state: State): void { - if (stage) { - this.sandboxProgress.transitionStages(stage, state); - } + // Dynamically update MultiStageOutput status + // const currentStage = this.sandboxProgress.getSandboxProgress(event)?.status; + // this.mso.updateStage(currentStage, 'inProgress'); + + // if (event.sandboxProcessObj) { + // this.mso.updateProgress(event.sandboxProcessObj, true); + // } } + // protected updateStage(stage: string | undefined, state: State): void { + // if (stage) { + // this.sandboxProgress.transitionStages(stage, state); + // this.mso.updateData(stage, state); + // } + // } + protected updateSandboxRequestData(): void { if (this.sandboxRequestData && this.latestSandboxProgressObj) { this.sandboxRequestData.sandboxProcessObject = this.latestSandboxProgressObj; From c46d2bc2be68b30c68eed56c01b884fb97447e85 Mon Sep 17 00:00:00 2001 From: soridalac Date: Tue, 17 Dec 2024 13:55:17 -0800 Subject: [PATCH 6/9] feat: update mso --- src/shared/sandboxCommandBase.ts | 88 +++++++++++--------------------- src/shared/sandboxProgress.ts | 10 ++-- 2 files changed, 36 insertions(+), 62 deletions(-) diff --git a/src/shared/sandboxCommandBase.ts b/src/shared/sandboxCommandBase.ts index bcd3b023..7abac720 100644 --- a/src/shared/sandboxCommandBase.ts +++ b/src/shared/sandboxCommandBase.ts @@ -22,7 +22,7 @@ import { StatusEvent, } from '@salesforce/core'; import { SandboxProgress } from './sandboxProgress.js'; -// import { State } from './stagedProgress.js'; +import { State } from './stagedProgress.js'; type SandboxData = { sandboxStatus: StatusEvent; @@ -97,7 +97,7 @@ export abstract class SandboxCommandBase extends SfCommand { options: { isAsync: boolean; alias?: string; setDefault?: boolean; prodOrg?: Org; tracksSource?: boolean } ): void { const mso = new MultiStageOutput({ - stages: ['Creating new sandbox', 'Authenticating'], + stages: ['Creating new sandbox', 'Authenticating', 'Done'], title: 'Create Sandbox', jsonEnabled: false, postStagesBlock: [ @@ -113,28 +113,12 @@ export abstract class SandboxCommandBase extends SfCommand { type: 'dynamic-key-value', bold: true, }, - { - label: 'Copy Progress', - get: (data): string | undefined => { - if (data?.sandboxStatus.sandboxProcessObj.CopyProgress) - return `${data?.sandboxStatus.sandboxProcessObj.CopyProgress}`; - }, - type: 'dynamic-key-value', - bold: true, - }, ], }); lifecycle.on('POLLING_TIME_OUT', async () => { this.pollingTimeOut = true; - this.warn('Sandbox creation process time out.'); - - if (this.latestSandboxProgressObj) { - const sandboxId = this.latestSandboxProgressObj.Id; - if (sandboxId) { - this.info(`Sandbox ID: ${sandboxId}`); - mso.updateData({ status: this.latestSandboxProgressObj.Status }); - } - } + mso.goto('Done'); + mso.updateData({ status: 'Polling timeout', id: 'N/A' }); return Promise.resolve(this.updateSandboxRequestData()); }); @@ -143,6 +127,9 @@ export abstract class SandboxCommandBase extends SfCommand { this.sandboxProgress.markPreviousStagesAsCompleted( results.Status !== 'Completed' ? results.Status : 'Authenticating' ); + mso.goto('Authenticating'); + mso.updateData({ status: 'Resuming process', id: results.Id }); + return Promise.resolve(this.updateSandboxRequestData()); }); @@ -150,7 +137,7 @@ export abstract class SandboxCommandBase extends SfCommand { this.latestSandboxProgressObj = results ?? this.latestSandboxProgressObj; this.updateSandboxRequestData(); if (!options.isAsync) { - // this.spinner.stop(); + mso.stop(); } // things that require data on latestSandboxProgressObj if (this.latestSandboxProgressObj) { @@ -160,11 +147,10 @@ export abstract class SandboxCommandBase extends SfCommand { }); const currentStage = progress.status; this.sandboxProgress.markPreviousStagesAsCompleted(currentStage); - // this.updateStage(currentStage, 'inProgress'); - this.updateProgress( - { sandboxProcessObj: this.latestSandboxProgressObj, sandboxRes: undefined }, - options.isAsync - ); + this.updateStage(currentStage, 'inProgress'); + mso.goto('Creating new sandbox'); + mso.updateData({ status: currentStage, id: this.latestSandboxProgressObj?.Id }); + mso.goto(progress.status); } if (this.pollingTimeOut) { this.warn(messages.getMessage('warning.ClientTimeoutWaitingForSandboxProcess', [this.action.toLowerCase()])); @@ -175,16 +161,13 @@ export abstract class SandboxCommandBase extends SfCommand { lifecycle.on(SandboxEvents.EVENT_STATUS, async (results: StatusEvent) => { this.latestSandboxProgressObj = results.sandboxProcessObj; - const sandboxId = this.latestSandboxProgressObj?.Id; - // results.sandboxProcessObj.Status; - if (sandboxId) { - this.info(`Sandbox ID: ${sandboxId}`); - } - this.updateSandboxRequestData(); - // const progress = this.sandboxProgress.getSandboxProgress(results); - // const currentStage = progress.status; - // this.updateStage(currentStage, 'inProgress'); + const progress = this.sandboxProgress.getSandboxProgress(results); + const currentStage = progress.status; + this.updateStage(currentStage, 'inProgress'); + mso.goto('Authenticating'); + mso.updateData({ status: currentStage, id: results.sandboxProcessObj.Id }); + return Promise.resolve(this.updateProgress(results, options.isAsync)); }); @@ -194,18 +177,15 @@ export abstract class SandboxCommandBase extends SfCommand { }); lifecycle.on(SandboxEvents.EVENT_RESULT, async (results: ResultEvent) => { - // this.latestSandboxProgressObj = results.sandboxProcessObj; - const sandboxId = results.sandboxProcessObj?.Id; - - if (sandboxId) { - this.info(`Sandbox created with ID: ${sandboxId}`); - } + this.latestSandboxProgressObj = results.sandboxProcessObj; this.updateSandboxRequestData(); this.sandboxProgress.markPreviousStagesAsCompleted(); this.updateProgress(results, options.isAsync); + if (!options.isAsync) { - this.progress.stop(); + mso.stop(); } + if (results.sandboxRes?.authUserName) { const authInfo = await AuthInfo.create({ username: results.sandboxRes?.authUserName }); await authInfo.handleAliasAndDefaultSettings({ @@ -218,6 +198,9 @@ export abstract class SandboxCommandBase extends SfCommand { this.removeSandboxProgressConfig(); this.updateProgress(results, options.isAsync); this.reportResults(results); + + mso.goto('Done'); + mso.updateData({ status: 'Completed', id: results.sandboxProcessObj.Id }); }); lifecycle.on(SandboxEvents.EVENT_MULTIPLE_SBX_PROCESSES, async (results: SandboxProcessObject[]) => { @@ -267,24 +250,15 @@ export abstract class SandboxCommandBase extends SfCommand { sandboxProcessObj: event.sandboxProcessObj, }; if (!isAsync) { - // this.spinner.status = this.sandboxProgress.formatProgressStatus(); + this.spinner.status = this.sandboxProgress.formatProgressStatus(); } - - // Dynamically update MultiStageOutput status - // const currentStage = this.sandboxProgress.getSandboxProgress(event)?.status; - // this.mso.updateStage(currentStage, 'inProgress'); - - // if (event.sandboxProcessObj) { - // this.mso.updateProgress(event.sandboxProcessObj, true); - // } } - // protected updateStage(stage: string | undefined, state: State): void { - // if (stage) { - // this.sandboxProgress.transitionStages(stage, state); - // this.mso.updateData(stage, state); - // } - // } + protected updateStage(stage: string | undefined, state: State): void { + if (stage) { + this.sandboxProgress.transitionStages(stage, state); + } + } protected updateSandboxRequestData(): void { if (this.sandboxRequestData && this.latestSandboxProgressObj) { diff --git a/src/shared/sandboxProgress.ts b/src/shared/sandboxProgress.ts index 6b6a97c2..69d4b762 100644 --- a/src/shared/sandboxProgress.ts +++ b/src/shared/sandboxProgress.ts @@ -66,17 +66,17 @@ export class SandboxProgress extends StagedProgress { } public formatProgressStatus(withClock = true): string { - const table = getSandboxTableAsText(undefined, this.statusData?.sandboxProcessObj); + // const table = getSandboxTableAsText(undefined, this.statusData?.sandboxProcessObj); return [ withClock && this.statusData ? `${getClockForSeconds(this.statusData.sandboxProgress.remainingWaitTime)} until timeout. ${ this.statusData.sandboxProgress.percentComplete ?? 0 }%` : undefined, - table, - '---------------------', - `Sandbox ${this.action ?? ''} Stages`, - this.formatStages(), + // table, + // '---------------------', + // `Sandbox ${this.action ?? ''} Stages`, + // this.formatStages(), ] .filter(isDefined) .join(os.EOL); From 8c394b36cc4f21989bceb62aaaecdaec38c7561b Mon Sep 17 00:00:00 2001 From: soridalac Date: Tue, 17 Dec 2024 13:57:52 -0800 Subject: [PATCH 7/9] fix: delete comment --- src/commands/org/create/sandbox.ts | 36 ------------------------------ 1 file changed, 36 deletions(-) diff --git a/src/commands/org/create/sandbox.ts b/src/commands/org/create/sandbox.ts index dad5d0de..7d9ada0e 100644 --- a/src/commands/org/create/sandbox.ts +++ b/src/commands/org/create/sandbox.ts @@ -188,7 +188,6 @@ export default class CreateSandbox extends SandboxCommandBase { const lifecycle = Lifecycle.getInstance(); - this.prodOrg = this.flags['target-org']; const sandboxReq = await this.createSandboxRequest(); @@ -204,61 +203,26 @@ export default class CreateSandbox extends SandboxCommandBase({ - // stages: this.flags.async - // ? ['Prepare request', 'Send request', 'Done'] - // : ['Prepare request', 'Send request', 'Waiting for org to respond', 'Done'], - // title: this.flags.async ? 'Create Sandbox (async)' : 'Create Sandbox', - // jsonEnabled: false, - // postStagesBlock: [ - // { - // label: 'Sandbox ID', - // get: (data) => data?.id, - // type: 'dynamic-key-value', - // bold: true, - // }, - // { - // label: 'Status', - // get: (data) => data?.status, - // type: 'dynamic-key-value', - // bold: true, - // }, - // ], - // }); - - // this.mso.goto('Prepare request', { status: 'Pending' }); if (!this.flags.async) { this.spinner.start('Sandbox Create'); - // this.mso.skipTo('Sandbox Create', { status: 'Pending' }); } - this.debug('Calling create with SandboxRequest: %s ', sandboxReq); try { - // this.mso.goto('Send request', { status: 'In Progress' }); const sandboxProcessObject = await this.prodOrg.createSandbox(sandboxReq, { wait: this.flags.wait, interval: this.flags['poll-interval'], async: this.flags.async, }); - // console.log('Sandbox Process Object', sandboxProcessObject); - - // this.mso.updateData({ status: sandboxProcessObject.Status, id: sandboxProcessObject.Id }); - this.latestSandboxProgressObj = sandboxProcessObject; this.saveSandboxProgressConfig(); - // this.mso.goto('Done', { status: sandboxProcessObject.Status, id: sandboxProcessObject.Id }); if (this.flags.async) { - // this.mso.goto('Waiting for org to respond', { status: 'Pending', id: sandboxProcessObject.Id }); - // this.mso.skipTo('Done'); - // this.mso.stop(); process.exitCode = 68; } return this.getSandboxCommandResponse(); } catch (err) { - // this.mso.error(); if (this.pollingTimeOut && this.latestSandboxProgressObj) { void lifecycle.emit(SandboxEvents.EVENT_ASYNC_RESULT, undefined); process.exitCode = 68; From a69235ca380a260826f6ce7879b331b2899ef318 Mon Sep 17 00:00:00 2001 From: soridalac Date: Wed, 18 Dec 2024 21:21:53 -0800 Subject: [PATCH 8/9] fix: update mso resume --- src/shared/sandboxCommandBase.ts | 136 ++++++++++++++++++++++++++----- src/shared/sandboxProgress.ts | 9 +- 2 files changed, 118 insertions(+), 27 deletions(-) diff --git a/src/shared/sandboxCommandBase.ts b/src/shared/sandboxCommandBase.ts index 7abac720..4da431d2 100644 --- a/src/shared/sandboxCommandBase.ts +++ b/src/shared/sandboxCommandBase.ts @@ -28,6 +28,7 @@ type SandboxData = { sandboxStatus: StatusEvent; status: string; id: string; + copyProgress: number; }; Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); @@ -98,27 +99,30 @@ export abstract class SandboxCommandBase extends SfCommand { ): void { const mso = new MultiStageOutput({ stages: ['Creating new sandbox', 'Authenticating', 'Done'], - title: 'Create Sandbox', + title: 'Sandbox Process', jsonEnabled: false, postStagesBlock: [ { - label: 'Sandbox ID', - get: (data): string | undefined => data?.id, + label: 'Status', + get: (data) => data?.status, type: 'dynamic-key-value', bold: true, }, { - label: 'Status', - get: (data): string | undefined => data?.status, + label: 'Sandbox ID', + get: (data) => data?.id, + type: 'static-key-value', + }, + { + label: 'Copy Progress', + get: (data) => `${data?.copyProgress ?? 0}%`, type: 'dynamic-key-value', - bold: true, }, ], }); lifecycle.on('POLLING_TIME_OUT', async () => { this.pollingTimeOut = true; - mso.goto('Done'); - mso.updateData({ status: 'Polling timeout', id: 'N/A' }); + mso.updateData({ status: 'Polling Timeout' }); return Promise.resolve(this.updateSandboxRequestData()); }); @@ -127,8 +131,25 @@ export abstract class SandboxCommandBase extends SfCommand { this.sandboxProgress.markPreviousStagesAsCompleted( results.Status !== 'Completed' ? results.Status : 'Authenticating' ); - mso.goto('Authenticating'); - mso.updateData({ status: 'Resuming process', id: results.Id }); + 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 }); + } else if (results.Status === 'Completed') { + mso.goto('Done'); + 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()); }); @@ -137,8 +158,40 @@ export abstract class SandboxCommandBase extends SfCommand { this.latestSandboxProgressObj = results ?? this.latestSandboxProgressObj; this.updateSandboxRequestData(); if (!options.isAsync) { - mso.stop(); + 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(); } + // 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({ @@ -149,9 +202,14 @@ export abstract class SandboxCommandBase extends SfCommand { this.sandboxProgress.markPreviousStagesAsCompleted(currentStage); this.updateStage(currentStage, 'inProgress'); mso.goto('Creating new sandbox'); - mso.updateData({ status: currentStage, id: this.latestSandboxProgressObj?.Id }); + mso.updateData({ + status: currentStage, + id: this.latestSandboxProgressObj?.Id, + copyProgress: this.latestSandboxProgressObj?.CopyProgress, + }); mso.goto(progress.status); } + if (this.pollingTimeOut) { this.warn(messages.getMessage('warning.ClientTimeoutWaitingForSandboxProcess', [this.action.toLowerCase()])); } @@ -165,9 +223,13 @@ export abstract class SandboxCommandBase extends SfCommand { const progress = this.sandboxProgress.getSandboxProgress(results); const currentStage = progress.status; this.updateStage(currentStage, 'inProgress'); - mso.goto('Authenticating'); - mso.updateData({ status: currentStage, id: results.sandboxProcessObj.Id }); + mso.goto('Authenticating'); + mso.updateData({ + status: currentStage, + id: results.sandboxProcessObj.Id, + copyProgress: results.sandboxProcessObj.CopyProgress, + }); return Promise.resolve(this.updateProgress(results, options.isAsync)); }); @@ -183,9 +245,48 @@ export abstract class SandboxCommandBase extends SfCommand { this.updateProgress(results, options.isAsync); if (!options.isAsync) { - mso.stop(); - } + 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', + id: results.sandboxProcessObj.Id, + copyProgress: results.sandboxProcessObj.CopyProgress, + }); + mso.stop(); if (results.sandboxRes?.authUserName) { const authInfo = await AuthInfo.create({ username: results.sandboxRes?.authUserName }); await authInfo.handleAliasAndDefaultSettings({ @@ -198,9 +299,6 @@ export abstract class SandboxCommandBase extends SfCommand { this.removeSandboxProgressConfig(); this.updateProgress(results, options.isAsync); this.reportResults(results); - - mso.goto('Done'); - mso.updateData({ status: 'Completed', id: results.sandboxProcessObj.Id }); }); lifecycle.on(SandboxEvents.EVENT_MULTIPLE_SBX_PROCESSES, async (results: SandboxProcessObject[]) => { diff --git a/src/shared/sandboxProgress.ts b/src/shared/sandboxProgress.ts index 69d4b762..59bb9905 100644 --- a/src/shared/sandboxProgress.ts +++ b/src/shared/sandboxProgress.ts @@ -66,17 +66,10 @@ export class SandboxProgress extends StagedProgress { } public formatProgressStatus(withClock = true): string { - // const table = getSandboxTableAsText(undefined, this.statusData?.sandboxProcessObj); return [ withClock && this.statusData - ? `${getClockForSeconds(this.statusData.sandboxProgress.remainingWaitTime)} until timeout. ${ - this.statusData.sandboxProgress.percentComplete ?? 0 - }%` + ? `${getClockForSeconds(this.statusData.sandboxProgress.remainingWaitTime)} until timeout.` : undefined, - // table, - // '---------------------', - // `Sandbox ${this.action ?? ''} Stages`, - // this.formatStages(), ] .filter(isDefined) .join(os.EOL); From 9e0a008713b1ce2a14cecd1c06c7e99cf0badf3f Mon Sep 17 00:00:00 2001 From: soridalac Date: Fri, 20 Dec 2024 08:29:32 -0800 Subject: [PATCH 9/9] 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 {