Update deletion flow to handle deployments without canonical deployments

This commit is contained in:
IshaVenikar 2025-02-04 15:04:46 +05:30
parent 2c71b8c95f
commit 027c88e148

View File

@ -1289,13 +1289,38 @@ export class Service {
},
})
// If the canonical deployment is not present then query the chain for the deployment record for backwards compatibility
if (!canonicalDeployment) {
log(`Canonical deployment for deployment with id ${deployment.id} not found`);
log(`Canonical deployment for deployment with id ${deployment.id} not found, querying the chain..`);
const currentDeploymentURL = `https://${(deployment.project.name).toLowerCase()}.${deployment.deployer.baseDomain}`;
const deploymentRecords =
await this.laconicRegistry.getDeploymentRecordsByFilter({
application: deployment.applicationRecordId,
url: currentDeploymentURL,
});
if (!deploymentRecords.length) {
log(
`No ApplicationDeploymentRecord found for URL ${currentDeploymentURL} and ApplicationDeploymentRecord id ${deployment.applicationDeploymentRecordId}`,
);
return false;
}
const dnsResult =
// Multiple records are fetched, take the latest record
const latestRecord = deploymentRecords
.sort((a, b) => new Date(b.createTime).getTime() - new Date(a.createTime).getTime())[0];
await this.laconicRegistry.createApplicationDeploymentRemovalRequest({
deploymentId: latestRecord.id,
deployerLrn: deployment.deployer.deployerLrn,
auctionId: deployment.project.auctionId,
payment: deployment.project.txHash
});
} else {
// If canonical deployment is found in the DB, then send the removal request with that deployment record Id
const result =
await this.laconicRegistry.createApplicationDeploymentRemovalRequest({
deploymentId: canonicalDeployment.applicationDeploymentRecordId!,
deployerLrn: canonicalDeployment.deployer.deployerLrn,
@ -1306,11 +1331,12 @@ export class Service {
await this.db.updateDeploymentById(canonicalDeployment.id, {
status: DeploymentStatus.Deleting,
applicationDeploymentRemovalRequestId:
dnsResult.applicationDeploymentRemovalRequestId,
result.applicationDeploymentRemovalRequestId,
applicationDeploymentRemovalRequestData:
dnsResult.applicationDeploymentRemovalRequestData,
result.applicationDeploymentRemovalRequestData,
});
}
}
const result =
await this.laconicRegistry.createApplicationDeploymentRemovalRequest({