Skip to content

Commit

Permalink
feat: support psg update awaiter timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
dieffrei committed Jan 20, 2025
1 parent a46c12b commit 258c783
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
8 changes: 7 additions & 1 deletion resources/schemas/sfdx-project.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,12 @@
"description": "Disable Entitlement filtering in source package,which skips entitlements that are already in the target org",
"default": false
},
"permissionsetGroupTimeout": {
"title": "Permission set group recalculation timeout",
"type": "integer",
"description": "Permission set group recalculation timeout",
"default": false
},
"disableTransitiveDependencyResolver": {
"title": "Disable Transitive Dependency Resolver",
"type": "boolean",
Expand Down Expand Up @@ -1183,4 +1189,4 @@
}
}
}
}
}
17 changes: 10 additions & 7 deletions src/core/package/packageInstallers/InstallPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export abstract class InstallPackage {
};
}
}

checkPackageDirectoryExists() {
let absPackageDirectory: string = path.join(this.sfpPackage.sourceDir, this.packageDirectory);
if (!fs.existsSync(absPackageDirectory)) {
Expand All @@ -107,11 +107,14 @@ export abstract class InstallPackage {
}

private async waitTillAllPermissionSetGroupIsUpdated() {
const projectConfig = ProjectConfig.getSFDXProjectConfig(this.sfpPackage.sourceDir);
try {
//Package Has Permission Set Group
let permissionSetGroupUpdateAwaiter: PermissionSetGroupUpdateAwaiter = new PermissionSetGroupUpdateAwaiter(
this.connection,
this.logger
this.logger,
6000,//TODO fix
projectConfig.plugins.sfp.permissionsetGroupTimeout
);
await permissionSetGroupUpdateAwaiter.waitTillAllPermissionSetGroupIsUpdated();
} catch (error) {
Expand Down Expand Up @@ -222,15 +225,15 @@ export abstract class InstallPackage {
if (skipIfPackageInstalled) {
let installationStatus = await this.sfpOrg.isArtifactInstalledInOrg(this.logger, this.sfpPackage);
return !installationStatus.isInstalled;
} else if(this.sfpPackage.packageType == PackageType.Diff)
} else if(this.sfpPackage.packageType == PackageType.Diff)
{
// If diff package, check if there are any changes to be deployed, else skip
if(!this.sfpPackage.destructiveChanges && this.sfpPackage.metadataCount==0)
{
{
return false;
}
}

return true; // Always install packages if skipIfPackageInstalled is false
}

Expand Down Expand Up @@ -363,7 +366,7 @@ export abstract class InstallPackage {

let analyzers = AnalyzerRegistry.getAnalyzers();
for (const analyzer of analyzers) {
if(await analyzer.isEnabled(this.sfpPackage, this.logger))
if(await analyzer.isEnabled(this.sfpPackage, this.logger))
{
SFPLogger.log(`Executing ${COLOR_KEY_MESSAGE(analyzer.getName())}`, LoggerLevel.INFO, this.logger);
this.sfpPackage = await analyzer.analyze(this.sfpPackage,componentSet, this.logger);
Expand Down Expand Up @@ -489,7 +492,7 @@ export abstract class InstallPackage {
deploymentOptions.rollBackOnError = true;
return deploymentOptions;
}

private getAStringOfSpecificTestClasses(apexTestClassses: string[]) {
let specifedTests = apexTestClassses.join();
return specifedTests;
Expand Down
22 changes: 21 additions & 1 deletion src/core/permsets/PermissionSetGroupUpdateAwaiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,36 @@ import { delay } from '../utils/Delay';
const psGroupQuery = `SELECT Id,MasterLabel,Status FROM PermissionSetGroup WHERE Status IN ('Updating', 'Outdated')`;

export default class PermissionSetGroupUpdateAwaiter {
constructor(private connection: Connection, private logger: Logger, private intervalBetweenRepeats = 60000) {}
private startTime: number;

constructor(
private connection: Connection,
private logger: Logger,
private intervalBetweenRepeats = 60000,
private timeoutInMs = 30 * 60 * 1000 // Default timeout of 30 minutes
) {
this.startTime = Date.now();
}

async waitTillAllPermissionSetGroupIsUpdated() {
SFPLogger.log(
`Checking status of permission sets group..`,
LoggerLevel.INFO,
this.logger
);

while (true) {
try {
// Check if timeout has been reached
if (Date.now() - this.startTime >= this.timeoutInMs) {
SFPLogger.log(

Check warning on line 31 in src/core/permsets/PermissionSetGroupUpdateAwaiter.ts

View check run for this annotation

Codecov / codecov/patch

src/core/permsets/PermissionSetGroupUpdateAwaiter.ts#L31

Added line #L31 was not covered by tests
`Timeout of ${this.timeoutInMs/1000} seconds reached. Proceeding with deployment regardless of PermissionSetGroup status`,
LoggerLevel.WARN,
this.logger
);
break;

Check warning on line 36 in src/core/permsets/PermissionSetGroupUpdateAwaiter.ts

View check run for this annotation

Codecov / codecov/patch

src/core/permsets/PermissionSetGroupUpdateAwaiter.ts#L36

Added line #L36 was not covered by tests
}

let records = await QueryHelper.query(psGroupQuery, this.connection, false);
if (records.length > 0) {
SFPLogger.log(
Expand Down

0 comments on commit 258c783

Please sign in to comment.