Skip to content

Commit

Permalink
fix(pool): make pools using snapshot pools respect max allocation (#104)
Browse files Browse the repository at this point in the history
* fix(pool): make pools fetching from snapshot pools respect max allocation atttribute

* fix(pool): ignore active scratch org limit for pools fetching from snapshot pools

* fix(pool): ensure correct calculation of scratch orgs to allocate for pools using snapshot pools

---------

Co-authored-by: Azlam <[email protected]>
  • Loading branch information
petter-eikeland and azlam-abdulsalam authored Aug 22, 2024
1 parent 8431a04 commit a39b7d5
Showing 1 changed file with 29 additions and 28 deletions.
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

0 comments on commit a39b7d5

Please sign in to comment.