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,27 +1289,53 @@ export class Service {
}, },
}) })
// If the canonical deployment is not present then query the chain for the deployment record for backwards compatibility
if (!canonicalDeployment) { 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}`;
return false; 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;
}
// 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];
const dnsResult =
await this.laconicRegistry.createApplicationDeploymentRemovalRequest({ await this.laconicRegistry.createApplicationDeploymentRemovalRequest({
deploymentId: canonicalDeployment.applicationDeploymentRecordId!, deploymentId: latestRecord.id,
deployerLrn: canonicalDeployment.deployer.deployerLrn, deployerLrn: deployment.deployer.deployerLrn,
auctionId: canonicalDeployment.project.auctionId, auctionId: deployment.project.auctionId,
payment: canonicalDeployment.project.txHash 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,
auctionId: canonicalDeployment.project.auctionId,
payment: canonicalDeployment.project.txHash
});
await this.db.updateDeploymentById(canonicalDeployment.id, { await this.db.updateDeploymentById(canonicalDeployment.id, {
status: DeploymentStatus.Deleting, status: DeploymentStatus.Deleting,
applicationDeploymentRemovalRequestId: applicationDeploymentRemovalRequestId:
dnsResult.applicationDeploymentRemovalRequestId, result.applicationDeploymentRemovalRequestId,
applicationDeploymentRemovalRequestData: applicationDeploymentRemovalRequestData:
dnsResult.applicationDeploymentRemovalRequestData, result.applicationDeploymentRemovalRequestData,
}); });
}
} }
const result = const result =