Skip to content
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(pool): make pools using snapshot pools respect max allocation #104

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 29 additions & 28 deletions src/core/scratchorg/pool/PoolCreateImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,37 +68,36 @@ export default class PoolCreateImpl extends PoolBaseImpl {

//Compute allocation
try {
if (!this.pool.snapshotPool) {
SFPLogger.log(COLOR_KEY_MESSAGE('Computing Allocation..'), LoggerLevel.INFO);
try {
this.totalToBeAllocated = await this.computeAllocation();
} catch (error) {
SFPLogger.log(COLOR_KEY_MESSAGE('Computing Allocation..'), LoggerLevel.INFO);
try {
this.totalToBeAllocated = await this.computeAllocation();
} catch (error) {
return err({
success: 0,
failed: 0,
message: `Unable to access fields on ScratchOrgInfo, Please check the profile being used`,
errorCode: PoolErrorCodes.PrerequisiteMissing,
});
}

if (this.totalToBeAllocated === 0) {
if (this.limits.ActiveScratchOrgs.Remaining > 0 || this.pool.snapshotPool) {
return err({
success: 0,
failed: 0,
message: `Unable to access fields on ScratchOrgInfo, Please check the profile being used`,
errorCode: PoolErrorCodes.PrerequisiteMissing,
message: `The tag provided ${this.pool.tag} is currently at the maximum capacity , No scratch orgs will be allocated`,
errorCode: PoolErrorCodes.Max_Capacity,
});
} else {
return err({
success: 0,
failed: 0,
message: `There is no capacity to create a pool at this time, Please try again later`,
errorCode: PoolErrorCodes.No_Capacity,
});
}

if (this.totalToBeAllocated === 0) {
if (this.limits.ActiveScratchOrgs.Remaining > 0) {
return err({
success: 0,
failed: 0,
message: `The tag provided ${this.pool.tag} is currently at the maximum capacity , No scratch orgs will be allocated`,
errorCode: PoolErrorCodes.Max_Capacity,
});
} else {
return err({
success: 0,
failed: 0,
message: `There is no capacity to create a pool at this time, Please try again later`,
errorCode: PoolErrorCodes.No_Capacity,
});
}
}

}
if (!this.pool.snapshotPool) {
//Generate Scratch Orgs
this.pool.scratchOrgs = await this.generateScratchOrgs(
this.pool,
Expand Down Expand Up @@ -164,7 +163,9 @@ export default class PoolCreateImpl extends PoolBaseImpl {
pool.to_satisfy_max =
pool.maxAllocation - pool.current_allocation > 0 ? pool.maxAllocation - pool.current_allocation : 0;

if (pool.to_satisfy_max > 0 && pool.to_satisfy_max <= remainingScratchOrgs) {
if (pool.snapshotPool && pool.to_satisfy_max > 0){
pool.to_allocate = pool.to_satisfy_max;
} else if(pool.to_satisfy_max > 0 && pool.to_satisfy_max <= remainingScratchOrgs){
pool.to_allocate = pool.to_satisfy_max;
} else if (pool.to_satisfy_max > 0 && pool.to_satisfy_max > remainingScratchOrgs) {
pool.to_allocate = remainingScratchOrgs;
Expand Down Expand Up @@ -329,7 +330,7 @@ export default class PoolCreateImpl extends PoolBaseImpl {
undefined,
undefined,
true,
this.pool.maxAllocation
this.pool.to_allocate
).execute()) as ScratchOrg[];
scratchOrgs = await scratchOrgInfoFetcher.getScratchOrgRecordId(scratchOrgs);

Expand Down
Loading