Update method to return webapp deployer records from registry

This commit is contained in:
Adw8 2024-10-17 13:10:13 +05:30 committed by IshaVenikar
parent 4bd111611d
commit b15d998ed2
5 changed files with 40 additions and 22 deletions

View File

@ -1,5 +1,4 @@
import { Entity, PrimaryColumn, Column, OneToMany } from 'typeorm';
import { Deployment } from './Deployment';
@Entity()
export class Deployer {

View File

@ -14,7 +14,7 @@ import {
ApplicationDeploymentRequest,
ApplicationDeploymentRemovalRequest
} from './entity/Deployment';
import { AppDeploymentRecord, AppDeploymentRemovalRecord, AuctionParams } from './types';
import { AppDeploymentRecord, AppDeploymentRemovalRecord, AuctionParams, DeployerRecord } from './types';
import { getConfig, getRepoDetails, sleep } from './utils';
const log = debug('snowball:registry');
@ -25,6 +25,7 @@ const APP_DEPLOYMENT_REQUEST_TYPE = 'ApplicationDeploymentRequest';
const APP_DEPLOYMENT_REMOVAL_REQUEST_TYPE = 'ApplicationDeploymentRemovalRequest';
const APP_DEPLOYMENT_RECORD_TYPE = 'ApplicationDeploymentRecord';
const APP_DEPLOYMENT_REMOVAL_RECORD_TYPE = 'ApplicationDeploymentRemovalRecord';
const WEBAPP_DEPLOYER_RECORD_TYPE = 'WebappDeployer'
const SLEEP_DURATION = 1000;
// TODO: Move registry code to registry-sdk/watcher-ts
@ -116,7 +117,7 @@ export class Registry {
this.registryConfig.privateKey,
fee
);
log("Result: ", result);
log(`Published application record ${result.id}`);
log('Application record data:', applicationRecord);
@ -291,32 +292,33 @@ export class Registry {
};
}
async getAuctionWinningDeployers(
async getAuctionWinningDeployerRecords(
auctionId: string
): Promise<string[]> {
): Promise<DeployerRecord[]> {
const records = await this.registry.getAuctionsByIds([auctionId]);
const auctionResult = records[0];
let deployerLrns = [];
let deployerRecords = [];
const { winnerAddresses } = auctionResult;
for (const auctionWinner of winnerAddresses) {
const deployerRecords = await this.registry.queryRecords(
const records = await this.registry.queryRecords(
{
paymentAddress: auctionWinner,
type: WEBAPP_DEPLOYER_RECORD_TYPE,
},
true
);
for (const record of deployerRecords) {
if (record.names && record.names.length > 0) {
deployerLrns.push(record.names[0]);
for (const record of records) {
if (record.id) {
deployerRecords.push(record);
break;
}
}
}
return deployerLrns;
return deployerRecords;
}
async releaseDeployerFunds(

View File

@ -140,7 +140,6 @@ type Deployer {
updatedAt: String!
}
type AuthResult {
token: String!
}

View File

@ -308,20 +308,21 @@ export class Service {
completedAuctionIds.includes(project.auctionId!)
);
for (const project of projectsToBedeployed) {
const deployerLrns = await this.laconicRegistry.getAuctionWinningDeployers(project.auctionId!);
if (!deployerLrns) {
for (const project of projectsToBedeployed) {
const deployers = await this.laconicRegistry.getAuctionWinningDeployerRecords(project!.auctionId!);
if (!deployers) {
log(`No winning deployer for auction ${project!.auctionId}`);
} else {
// Update project with deployer LRNs
await this.db.updateProjectById(project.id!, {
deployerLrns
});
// TODO:Update project with deployer LRNs
// await this.db.updateProjectById(project.id!, {
// deployers
// });
for (const deployer of deployerLrns) {
for (const deployer of deployers) {
log(`Creating deployment for deployer LRN ${deployer}`);
await this.createDeploymentFromAuction(project, deployer);
await this.createDeploymentFromAuction(project, deployer.names[0]);
}
}
}

View File

@ -82,3 +82,20 @@ export interface EnvironmentVariables {
key: string,
value: string,
}
export interface DeployerRecord {
id: string;
names: string[];
owners: string[];
bondId: string;
createTime: string;
expiryTime: string;
attributes: {
apiUrl: string;
name: string;
paymentAddress: string;
publicKey: string;
type: string;
version: string;
};
}