-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: handle multiple sandbox processes in resumable state #944
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,6 +83,7 @@ export enum SandboxEvents { | |
EVENT_RESULT = 'result', | ||
EVENT_AUTH = 'auth', | ||
EVENT_RESUME = 'resume', | ||
EVENT_MULTIPLE_SBX_PROCESSES = 'multipleMatchingSbxProcesses', | ||
} | ||
|
||
export interface SandboxUserAuthResponse { | ||
|
@@ -246,11 +247,11 @@ export class Org extends AsyncOptionalCreatable<Org.Options> { | |
} | ||
|
||
/** | ||
* resume a sandbox creation from a production org | ||
* 'this' needs to be a production org with sandbox licenses available | ||
* Resume a sandbox creation from a production org. | ||
* `this` needs to be a production org with sandbox licenses available. | ||
* | ||
* @param resumeSandboxRequest SandboxRequest options to create the sandbox with | ||
* @param options Wait: The amount of time to wait (default: 30 minutes) before timing out, | ||
* @param options Wait: The amount of time to wait (default: 0 minutes) before timing out, | ||
* Interval: The time interval (default: 30 seconds) between polling | ||
*/ | ||
public async resumeSandbox( | ||
|
@@ -264,10 +265,23 @@ export class Org extends AsyncOptionalCreatable<Org.Options> { | |
this.logger.debug(resumeSandboxRequest, 'ResumeSandbox called with ResumeSandboxRequest'); | ||
let sandboxCreationProgress: SandboxProcessObject; | ||
// seed the sandboxCreationProgress via the resumeSandboxRequest options | ||
if (resumeSandboxRequest.SandboxName) { | ||
sandboxCreationProgress = await this.querySandboxProcessBySandboxName(resumeSandboxRequest.SandboxName); | ||
} else if (resumeSandboxRequest.SandboxProcessObjId) { | ||
if (resumeSandboxRequest.SandboxProcessObjId) { | ||
sandboxCreationProgress = await this.querySandboxProcessById(resumeSandboxRequest.SandboxProcessObjId); | ||
} else if (resumeSandboxRequest.SandboxName) { | ||
try { | ||
// There can be multiple sandbox processes returned when querying by name. Use the most recent | ||
// process and fire a warning event with all processes. | ||
sandboxCreationProgress = await this.querySandboxProcessBySandboxName(resumeSandboxRequest.SandboxName); | ||
} catch (err) { | ||
if (err instanceof SfError && err.name === 'SingleRecordQuery_MultipleRecords' && err.data) { | ||
const sbxProcesses = err.data as SandboxProcessObject[]; | ||
// 0 index will always be the most recently created process since the query sorts on created date desc. | ||
sandboxCreationProgress = sbxProcesses[0]; | ||
await Lifecycle.getInstance().emit(SandboxEvents.EVENT_MULTIPLE_SBX_PROCESSES, sbxProcesses); | ||
} else { | ||
throw err; | ||
} | ||
} | ||
} else { | ||
throw messages.createError('sandboxNotFound', [ | ||
resumeSandboxRequest.SandboxName ?? resumeSandboxRequest.SandboxProcessObjId, | ||
|
@@ -1332,9 +1346,7 @@ export class Org extends AsyncOptionalCreatable<Org.Options> { | |
let waitingOnAuth = false; | ||
const pollingClient = await PollingClient.create({ | ||
poll: async (): Promise<StatusResult> => { | ||
const sandboxProcessObj = await this.querySandboxProcessBySandboxInfoId( | ||
options.sandboxProcessObj.SandboxInfoId | ||
); | ||
const sandboxProcessObj = await this.querySandboxProcessById(options.sandboxProcessObj.Id); | ||
// check to see if sandbox can authenticate via sandboxAuth endpoint | ||
const sandboxInfo = await this.sandboxSignupComplete(sandboxProcessObj); | ||
if (sandboxInfo) { | ||
|
@@ -1377,10 +1389,19 @@ export class Org extends AsyncOptionalCreatable<Org.Options> { | |
* @private | ||
*/ | ||
private async querySandboxProcess(where: string): Promise<SandboxProcessObject> { | ||
const queryStr = `SELECT Id, Status, SandboxName, SandboxInfoId, LicenseType, CreatedDate, CopyProgress, SandboxOrganization, SourceId, Description, EndDate FROM SandboxProcess WHERE ${where} AND Status != 'D'`; | ||
return this.connection.singleRecordQuery(queryStr, { | ||
tooling: true, | ||
}); | ||
const soql = `SELECT Id, Status, SandboxName, SandboxInfoId, LicenseType, CreatedDate, CopyProgress, SandboxOrganization, SourceId, Description, EndDate FROM SandboxProcess WHERE ${where} ORDER BY CreatedDate DESC`; | ||
const result = (await this.connection.tooling.query<SandboxProcessObject>(soql)).records.filter( | ||
(item) => !item.Status.startsWith('Del') | ||
); | ||
if (result.length === 0) { | ||
throw new SfError(`No record found for ${soql}`, SingleRecordQueryErrors.NoRecords); | ||
} | ||
if (result.length > 1) { | ||
const err = new SfError('The query returned more than 1 record', SingleRecordQueryErrors.MultipleRecords); | ||
err.data = result; | ||
throw err; | ||
} | ||
return result[0]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is mostly what Jochen's PR is, with some additions to the query to |
||
} | ||
/** | ||
* determines if the sandbox has successfully been created | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer the SandboxProcessId over name since it's unique.