Check for auction status in a loop
This commit is contained in:
parent
8c824f065b
commit
42d35cae84
@ -29,8 +29,8 @@
|
||||
|
||||
[registryConfig]
|
||||
fetchDeploymentRecordDelay = 5000
|
||||
restEndpoint = "http://localhost:1317"
|
||||
gqlEndpoint = "http://localhost:9473/api"
|
||||
checkAuctionStatusDelay = 5000
|
||||
restEndpoint = "http://dss-daemon.test1.wireitin.com:26657"
|
||||
chainId = "laconic_9000-1"
|
||||
privateKey = ""
|
||||
bondId = ""
|
||||
@ -41,11 +41,11 @@
|
||||
gasPrice = "1"
|
||||
|
||||
[auction]
|
||||
commitFee = 1000
|
||||
commitsDuration = 60s
|
||||
revealFee = 1000
|
||||
revealsDuration = 60s
|
||||
denom = alnt
|
||||
commitFee = "1000"
|
||||
commitsDuration = "60s"
|
||||
revealFee = "1000"
|
||||
revealsDuration = "60s"
|
||||
denom = "alnt"
|
||||
|
||||
[misc]
|
||||
projectDomain = "apps.snowballtools.com"
|
||||
|
@ -34,6 +34,7 @@ export interface RegistryConfig {
|
||||
privateKey: string;
|
||||
bondId: string;
|
||||
fetchDeploymentRecordDelay: number;
|
||||
checkAuctionStatusDelay: number;
|
||||
authority: string;
|
||||
fee: {
|
||||
gas: string;
|
||||
|
@ -49,9 +49,6 @@ export class Project {
|
||||
@Column('varchar', { nullable: true })
|
||||
auctionId?: string | null;
|
||||
|
||||
@Column('varchar', { nullable: true })
|
||||
auctionStatus?: string | null;
|
||||
|
||||
@Column('varchar', { nullable: true })
|
||||
deployerLrn?: string[] | null;
|
||||
|
||||
|
@ -6,6 +6,7 @@ import { DeepPartial } from 'typeorm';
|
||||
import { Octokit } from 'octokit';
|
||||
|
||||
import { Registry as LaconicRegistry, parseGasAndFees } from '@cerc-io/registry-sdk';
|
||||
import { Auction } from '@cerc-io/registry-sdk/dist/proto/cerc/auction/v1/auction';
|
||||
|
||||
import { RegistryConfig } from './config';
|
||||
import {
|
||||
@ -328,7 +329,7 @@ export class Registry {
|
||||
const records = await this.registry.getAuctionsByIds([auctionId]);
|
||||
const auctionResult = records[0];
|
||||
|
||||
let deployerLrns = [];
|
||||
let deployerLrns = [];
|
||||
const { winnerAddresses } = auctionResult.auction;
|
||||
|
||||
for (const auctionWinner of winnerAddresses) {
|
||||
@ -441,6 +442,18 @@ export class Registry {
|
||||
};
|
||||
}
|
||||
|
||||
async getCompletedAuctionIds(auctionIds: string[] | null | undefined): Promise<string[]> {
|
||||
if(auctionIds === null || auctionIds === undefined) {
|
||||
return [];
|
||||
}
|
||||
const auctions = await this.registry.getAuctionsByIds(auctionIds);
|
||||
const completedAuctions = auctions
|
||||
.filter((auction: Auction) => auction.status === 'completed')
|
||||
.map((auction: Auction) => auction.id);
|
||||
|
||||
return completedAuctions;
|
||||
}
|
||||
|
||||
getLrn(appName: string): string {
|
||||
assert(this.registryConfig.authority, "Authority doesn't exist");
|
||||
return `lrn://${this.registryConfig.authority}/applications/${appName}`;
|
||||
|
@ -67,7 +67,6 @@ type Project {
|
||||
description: String
|
||||
deployerLrn: [String]
|
||||
auctionId: String
|
||||
auctionStatus: String
|
||||
template: String
|
||||
framework: String
|
||||
webhooks: [String!]
|
||||
|
@ -1,6 +1,6 @@
|
||||
import assert from 'assert';
|
||||
import debug from 'debug';
|
||||
import { DeepPartial, FindOptionsWhere } from 'typeorm';
|
||||
import { DeepPartial, FindOptionsWhere, IsNull } from 'typeorm';
|
||||
import { Octokit, RequestError } from 'octokit';
|
||||
|
||||
import { OAuthApp } from '@octokit/oauth-app';
|
||||
@ -263,6 +263,44 @@ export class Service {
|
||||
await Promise.all(deploymentUpdatePromises);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for auction status for all ongoing auctions
|
||||
* Calls the createDeploymentFromAuction method for deployments with completed auctions
|
||||
*/
|
||||
async checkAuctionStatus(
|
||||
): Promise<void> {
|
||||
// Deployment should be in building state and should not have domain.
|
||||
const deployments = await this.db.getDeployments({
|
||||
where: {
|
||||
status: DeploymentStatus.Building,
|
||||
domain: IsNull()
|
||||
},
|
||||
});
|
||||
|
||||
// Check the auctionId for those deployments with auctions
|
||||
const auctionIds = deployments
|
||||
.filter(deployment => deployment.project && deployment.project.auctionId)
|
||||
.map(deployment => deployment.project!.auctionId) as string[];
|
||||
// Get all the auctions for those ids with auction status completed
|
||||
const completedAuctionIds = await this.registry.getCompletedAuctionIds(auctionIds);
|
||||
// If the deplyer lrn array is empty then call createDeploymentFromAuction
|
||||
const auctionDeployments = deployments.filter(deployment =>
|
||||
completedAuctionIds.includes(deployment.project!.auctionId!) &&
|
||||
deployment.project!.deployerLrn?.length === 0
|
||||
);
|
||||
|
||||
for (const auctionDeployment of auctionDeployments) {
|
||||
await this.createDeploymentFromAuction(
|
||||
'user id',
|
||||
auctionDeployment.project!.auctionId!,
|
||||
auctionDeployment
|
||||
);
|
||||
}
|
||||
this.deployRecordCheckTimeout = setTimeout(() => {
|
||||
this.checkAuctionStatus();
|
||||
}, this.config.registryConfig.fetchDeploymentRecordDelay);
|
||||
}
|
||||
|
||||
async getUser(userId: string): Promise<User | null> {
|
||||
return this.db.getUser({
|
||||
where: {
|
||||
@ -645,13 +683,10 @@ export class Service {
|
||||
});
|
||||
|
||||
// Save deployer lrn only if present
|
||||
let updateData: Partial<Project> = {};
|
||||
if (lrn) {
|
||||
updateData.deployerLrn = [lrn];
|
||||
newDeployment.project.deployerLrn = [lrn];
|
||||
}
|
||||
|
||||
await this.db.updateProjectById(data.project.id!, updateData);
|
||||
|
||||
return newDeployment;
|
||||
}
|
||||
|
||||
@ -659,6 +694,7 @@ export class Service {
|
||||
userId: string,
|
||||
auctionId: string,
|
||||
// take project data
|
||||
// project: DeepPartial<Project>,
|
||||
data: DeepPartial<Deployment>,
|
||||
) {
|
||||
// TODO: If data.domain is present then call createDeployment (don't need auction)
|
||||
@ -727,7 +763,11 @@ export class Service {
|
||||
});
|
||||
}
|
||||
|
||||
return newDeployment;
|
||||
// update project with deployerlrns
|
||||
|
||||
await this.db.updateProjectById(data.project?.id!, {
|
||||
deployerLrn: deployerLrns
|
||||
})
|
||||
}
|
||||
|
||||
async addProjectFromTemplate(
|
||||
|
Loading…
Reference in New Issue
Block a user