Check for auction status in a loop
This commit is contained in:
parent
8c824f065b
commit
42d35cae84
@ -29,8 +29,8 @@
|
|||||||
|
|
||||||
[registryConfig]
|
[registryConfig]
|
||||||
fetchDeploymentRecordDelay = 5000
|
fetchDeploymentRecordDelay = 5000
|
||||||
restEndpoint = "http://localhost:1317"
|
checkAuctionStatusDelay = 5000
|
||||||
gqlEndpoint = "http://localhost:9473/api"
|
restEndpoint = "http://dss-daemon.test1.wireitin.com:26657"
|
||||||
chainId = "laconic_9000-1"
|
chainId = "laconic_9000-1"
|
||||||
privateKey = ""
|
privateKey = ""
|
||||||
bondId = ""
|
bondId = ""
|
||||||
@ -41,11 +41,11 @@
|
|||||||
gasPrice = "1"
|
gasPrice = "1"
|
||||||
|
|
||||||
[auction]
|
[auction]
|
||||||
commitFee = 1000
|
commitFee = "1000"
|
||||||
commitsDuration = 60s
|
commitsDuration = "60s"
|
||||||
revealFee = 1000
|
revealFee = "1000"
|
||||||
revealsDuration = 60s
|
revealsDuration = "60s"
|
||||||
denom = alnt
|
denom = "alnt"
|
||||||
|
|
||||||
[misc]
|
[misc]
|
||||||
projectDomain = "apps.snowballtools.com"
|
projectDomain = "apps.snowballtools.com"
|
||||||
|
@ -34,6 +34,7 @@ export interface RegistryConfig {
|
|||||||
privateKey: string;
|
privateKey: string;
|
||||||
bondId: string;
|
bondId: string;
|
||||||
fetchDeploymentRecordDelay: number;
|
fetchDeploymentRecordDelay: number;
|
||||||
|
checkAuctionStatusDelay: number;
|
||||||
authority: string;
|
authority: string;
|
||||||
fee: {
|
fee: {
|
||||||
gas: string;
|
gas: string;
|
||||||
|
@ -49,9 +49,6 @@ export class Project {
|
|||||||
@Column('varchar', { nullable: true })
|
@Column('varchar', { nullable: true })
|
||||||
auctionId?: string | null;
|
auctionId?: string | null;
|
||||||
|
|
||||||
@Column('varchar', { nullable: true })
|
|
||||||
auctionStatus?: string | null;
|
|
||||||
|
|
||||||
@Column('varchar', { nullable: true })
|
@Column('varchar', { nullable: true })
|
||||||
deployerLrn?: string[] | null;
|
deployerLrn?: string[] | null;
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import { DeepPartial } from 'typeorm';
|
|||||||
import { Octokit } from 'octokit';
|
import { Octokit } from 'octokit';
|
||||||
|
|
||||||
import { Registry as LaconicRegistry, parseGasAndFees } from '@cerc-io/registry-sdk';
|
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 { RegistryConfig } from './config';
|
||||||
import {
|
import {
|
||||||
@ -328,7 +329,7 @@ export class Registry {
|
|||||||
const records = await this.registry.getAuctionsByIds([auctionId]);
|
const records = await this.registry.getAuctionsByIds([auctionId]);
|
||||||
const auctionResult = records[0];
|
const auctionResult = records[0];
|
||||||
|
|
||||||
let deployerLrns = [];
|
let deployerLrns = [];
|
||||||
const { winnerAddresses } = auctionResult.auction;
|
const { winnerAddresses } = auctionResult.auction;
|
||||||
|
|
||||||
for (const auctionWinner of winnerAddresses) {
|
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 {
|
getLrn(appName: string): string {
|
||||||
assert(this.registryConfig.authority, "Authority doesn't exist");
|
assert(this.registryConfig.authority, "Authority doesn't exist");
|
||||||
return `lrn://${this.registryConfig.authority}/applications/${appName}`;
|
return `lrn://${this.registryConfig.authority}/applications/${appName}`;
|
||||||
|
@ -67,7 +67,6 @@ type Project {
|
|||||||
description: String
|
description: String
|
||||||
deployerLrn: [String]
|
deployerLrn: [String]
|
||||||
auctionId: String
|
auctionId: String
|
||||||
auctionStatus: String
|
|
||||||
template: String
|
template: String
|
||||||
framework: String
|
framework: String
|
||||||
webhooks: [String!]
|
webhooks: [String!]
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import debug from 'debug';
|
import debug from 'debug';
|
||||||
import { DeepPartial, FindOptionsWhere } from 'typeorm';
|
import { DeepPartial, FindOptionsWhere, IsNull } from 'typeorm';
|
||||||
import { Octokit, RequestError } from 'octokit';
|
import { Octokit, RequestError } from 'octokit';
|
||||||
|
|
||||||
import { OAuthApp } from '@octokit/oauth-app';
|
import { OAuthApp } from '@octokit/oauth-app';
|
||||||
@ -263,6 +263,44 @@ export class Service {
|
|||||||
await Promise.all(deploymentUpdatePromises);
|
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> {
|
async getUser(userId: string): Promise<User | null> {
|
||||||
return this.db.getUser({
|
return this.db.getUser({
|
||||||
where: {
|
where: {
|
||||||
@ -645,13 +683,10 @@ export class Service {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Save deployer lrn only if present
|
// Save deployer lrn only if present
|
||||||
let updateData: Partial<Project> = {};
|
|
||||||
if (lrn) {
|
if (lrn) {
|
||||||
updateData.deployerLrn = [lrn];
|
newDeployment.project.deployerLrn = [lrn];
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.db.updateProjectById(data.project.id!, updateData);
|
|
||||||
|
|
||||||
return newDeployment;
|
return newDeployment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -659,6 +694,7 @@ export class Service {
|
|||||||
userId: string,
|
userId: string,
|
||||||
auctionId: string,
|
auctionId: string,
|
||||||
// take project data
|
// take project data
|
||||||
|
// project: DeepPartial<Project>,
|
||||||
data: DeepPartial<Deployment>,
|
data: DeepPartial<Deployment>,
|
||||||
) {
|
) {
|
||||||
// TODO: If data.domain is present then call createDeployment (don't need auction)
|
// 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(
|
async addProjectFromTemplate(
|
||||||
|
Loading…
Reference in New Issue
Block a user