Skip to content

Commit

Permalink
feat: update mso with create/refresh/resume sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
soridalac committed Dec 20, 2024
1 parent a69235c commit 9e0a008
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 96 deletions.
3 changes: 0 additions & 3 deletions src/commands/org/create/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,6 @@ export default class CreateSandbox extends SandboxCommandBase<SandboxCommandResp
tracksSource: this.flags['no-track-source'] === true ? false : undefined,
});

if (!this.flags.async) {
this.spinner.start('Sandbox Create');
}
this.debug('Calling create with SandboxRequest: %s ', sandboxReq);

try {
Expand Down
4 changes: 0 additions & 4 deletions src/commands/org/refresh/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ export default class RefreshSandbox extends SandboxCommandBase<SandboxCommandRes
this.initSandboxProcessData(this.sbxConfig);

try {
if (!this.flags.async) {
this.spinner.start('Sandbox Refresh');
}

const sandboxProcessObject = await this.prodOrg.refreshSandbox(updateableSandboxInfo, {
wait: this.flags['wait'],
interval: this.flags['poll-interval'],
Expand Down
4 changes: 0 additions & 4 deletions src/commands/org/resume/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,6 @@ export default class ResumeSandbox extends SandboxCommandBase<SandboxCommandResp

const sandboxReq = this.createResumeSandboxRequest();

if (this.flags.wait?.seconds && this.flags.wait.seconds > 0) {
this.spinner.start(`Resume ${this.sandboxRequestData.action ?? 'Create/Refresh'}`);
}

this.debug('Calling resume with ResumeSandboxRequest: %s ', sandboxReq);

try {
Expand Down
98 changes: 13 additions & 85 deletions src/shared/sandboxCommandBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,7 @@ export abstract class SandboxCommandBase<T> extends SfCommand<T> {

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 });
Expand All @@ -141,57 +137,17 @@ export abstract class SandboxCommandBase<T> extends SfCommand<T> {
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({
Expand Down Expand Up @@ -224,13 +180,13 @@ export abstract class SandboxCommandBase<T> extends SfCommand<T> {
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) => {
Expand All @@ -242,44 +198,20 @@ export abstract class SandboxCommandBase<T> extends SfCommand<T> {
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',
Expand All @@ -297,7 +229,7 @@ export abstract class SandboxCommandBase<T> extends SfCommand<T> {
});
}
this.removeSandboxProgressConfig();
this.updateProgress(results, options.isAsync);
this.updateProgress(results);
this.reportResults(results);
});

Expand Down Expand Up @@ -337,8 +269,7 @@ export abstract class SandboxCommandBase<T> extends SfCommand<T> {
}

protected updateProgress(
event: StatusEvent | (Omit<ResultEvent, 'sandboxRes'> & { sandboxRes?: ResultEvent['sandboxRes'] }),
isAsync: boolean
event: StatusEvent | (Omit<ResultEvent, 'sandboxRes'> & { sandboxRes?: ResultEvent['sandboxRes'] })
): void {
const sandboxProgress = this.sandboxProgress.getSandboxProgress(event);
this.sandboxUsername = (event as ResultEvent).sandboxRes?.authUserName;
Expand All @@ -347,9 +278,6 @@ export abstract class SandboxCommandBase<T> extends SfCommand<T> {
sandboxProgress,
sandboxProcessObj: event.sandboxProcessObj,
};
if (!isAsync) {
this.spinner.status = this.sandboxProgress.formatProgressStatus();
}
}

protected updateStage(stage: string | undefined, state: State): void {
Expand Down

0 comments on commit 9e0a008

Please sign in to comment.