Release funds only on first deployment
All checks were successful
Lint / lint (20.x) (pull_request) Successful in 4m57s

This commit is contained in:
IshaVenikar 2024-10-18 11:35:32 +05:30
parent e497ac2228
commit 28db7c24e8
6 changed files with 36 additions and 26 deletions

View File

@ -3,7 +3,9 @@ import {
DeepPartial,
FindManyOptions,
FindOneOptions,
FindOptionsWhere
FindOptionsWhere,
IsNull,
Not
} from 'typeorm';
import path from 'path';
import debug from 'debug';
@ -151,14 +153,19 @@ export class Database {
}
async allProjectsWithoutDeployments(): Promise<Project[]> {
const projectRepository = this.dataSource.getRepository(Project);
const allProjects = await this.getProjects({
where: {
auctionId: Not(IsNull()),
},
relations: ['deployments'],
withDeleted: true,
});
const projects = await projectRepository
.createQueryBuilder('project')
.leftJoinAndSelect('project.deployments', 'deployment', 'deployment.deletedAt IS NULL') // Join only non-soft-deleted deployments
.where('deployment.id IS NULL') // Get projects where no deployments are present
.andWhere('project.auctionId IS NOT NULL') // Ensure auctionId is not null
.getMany();
const projects = allProjects.filter(project => {
if (project.deletedAt !== null) return false;
return project.deployments.length === 0;
});
return projects;
}

View File

@ -432,6 +432,10 @@ export class Registry {
}
async getCompletedAuctionIds(auctionIds: string[]): Promise<string[]> {
if (auctionIds.length === 0) {
return [];
}
const auctions = await this.registry.getAuctionsByIds(auctionIds);
const completedAuctions = auctions

View File

@ -247,7 +247,6 @@ type Query {
projectMembers(projectId: String!): [ProjectMember!]
searchProjects(searchText: String!): [Project!]
getAuctionData(auctionId: String!): Auction!
releaseDeployerFundsByProjectId(projectId: String!): Auction!
domains(projectId: String!, filter: FilterDomainsInput): [Domain]
}

View File

@ -173,6 +173,9 @@ export class Service {
where: records.map((record) => ({
applicationDeploymentRequestId: record.attributes.request,
})),
relations: {
project: true,
},
order: {
createdAt: 'DESC',
},
@ -189,8 +192,6 @@ export class Service {
// Update deployment data for ApplicationDeploymentRecords
const deploymentUpdatePromises = records.map(async (record) => {
const deployment = recordToDeploymentsMap[record.attributes.request];
const project = await this.getProjectById(deployment.projectId)
assert(project)
const parts = record.attributes.url.replace('https://', '').split('.');
const baseDomain = parts.slice(1).join('.');
@ -204,19 +205,21 @@ export class Service {
await this.db.updateDeploymentById(deployment.id, deployment);
const baseDomains = project.baseDomains || [];
const baseDomains = deployment.project.baseDomains || [];
if (!baseDomains.includes(baseDomain)) {
baseDomains.push(baseDomain);
}
// Release deployer funds on successful deployment
const fundsReleased = await this.releaseDeployerFundsByProjectId(project.id);
if (!deployment.project.fundsReleased) {
const fundsReleased = await this.releaseDeployerFundsByProjectId(deployment.projectId);
await this.db.updateProjectById(project.id, {
baseDomains,
fundsReleased,
})
await this.db.updateProjectById(deployment.projectId, {
baseDomains,
fundsReleased,
});
}
log(
`Updated deployment ${deployment.id} with URL ${record.attributes.url}`,
@ -296,7 +299,7 @@ export class Service {
async checkAuctionStatus(): Promise<void> {
const projects = await this.db.allProjectsWithoutDeployments();
const validAuctionIds = projects.map((project) => project.auctionId!)
const validAuctionIds = projects.map((project) => project.auctionId)
.filter((id): id is string => Boolean(id));
const completedAuctionIds = await this.laconicRegistry.getCompletedAuctionIds(validAuctionIds);
@ -305,7 +308,7 @@ export class Service {
);
for (const project of projectsToBedeployed) {
const deployerLrns = await this.laconicRegistry.getAuctionWinningDeployers(project!.auctionId!);
const deployerLrns = await this.laconicRegistry.getAuctionWinningDeployers(project.auctionId!);
if (!deployerLrns) {
log(`No winning deployer for auction ${project!.auctionId}`);
@ -1271,6 +1274,7 @@ export class Service {
if (!project || !project.auctionId) {
log(`Project ${projectId} ${!project ? 'not found' : 'does not have an auction'}`);
return false;
}
@ -1279,10 +1283,12 @@ export class Service {
if (auction.auction.fundsReleased) {
log(`Funds released for auction ${project.auctionId}`);
await this.db.updateProjectById(projectId, { fundsReleased: true });
return true;
}
log(`Error releasing funds for auction ${project.auctionId}`);
return false;
}
}

View File

@ -39,9 +39,7 @@ export const AuctionCard = ({ project }: { project: Project }) => {
const intervalId = setInterval(checkAuctionStatus, WAIT_DURATION);
return () => clearInterval(intervalId);
}
}, [auctionStatus, checkAuctionStatus]);
useEffect(() => {
if (auctionStatus === 'completed') {
const fetchUpdatedProject = async () => {
// Wait for 5 secs since the project is not immediately updated with deployer LRNs

View File

@ -23,12 +23,8 @@ const Id = () => {
const handleSetupDomain = async () => {
if (id) {
// console.log('id', id);
// console.log('getting project for id', id);
const project = await client.getProject(id);
// console.log('project found:', project);
if (project && project.project) {
// console.log('project:', project.project);
setProject(project.project);
}
} else {
@ -38,7 +34,7 @@ const Id = () => {
useEffect(() => {
handleSetupDomain();
});
}, []);
return (
<>