mirror of
https://github.com/Canner/WrenAI.git
synced 2026-10-29 17:51:48 +08:00
add inprogress status when check deploy status (#87)
This commit is contained in:
@@ -11,12 +11,14 @@ export interface Deploy {
|
||||
}
|
||||
|
||||
export enum DeployStatusEnum {
|
||||
IN_PROGRESS = 'IN_PROGRESS',
|
||||
SUCCESS = 'SUCCESS',
|
||||
FAILED = 'FAILED',
|
||||
}
|
||||
|
||||
export interface IDeployLogRepository extends IBasicRepository<Deploy> {
|
||||
findLastProjectDeployLog(projectId: number): Promise<Deploy | null>;
|
||||
findInProgressProjectDeployLog(projectId: number): Promise<Deploy | null>;
|
||||
}
|
||||
|
||||
export class DeployLogRepository
|
||||
@@ -38,4 +40,19 @@ export class DeployLogRepository
|
||||
.first();
|
||||
return (res && this.transformFromDBData(res)) || null;
|
||||
}
|
||||
|
||||
public async findInProgressProjectDeployLog(projectId: number) {
|
||||
const res = await this.knex
|
||||
.select('*')
|
||||
.from(this.tableName)
|
||||
.where(
|
||||
this.transformToDBData({
|
||||
projectId,
|
||||
status: DeployStatusEnum.IN_PROGRESS,
|
||||
}),
|
||||
)
|
||||
.orderBy('created_at', 'desc')
|
||||
.first();
|
||||
return (res && this.transformFromDBData(res)) || null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,12 @@ import { DeployResponse } from '../services/deployService';
|
||||
const logger = getLogger('ModelResolver');
|
||||
logger.level = 'debug';
|
||||
|
||||
export enum SyncStatusEnum {
|
||||
IN_PROGRESS = 'IN_PROGRESS',
|
||||
SYNCRONIZED = 'SYNCRONIZED',
|
||||
UNSYNCRONIZED = 'UNSYNCRONIZED',
|
||||
}
|
||||
|
||||
export class ModelResolver {
|
||||
constructor() {
|
||||
this.listModels = this.listModels.bind(this);
|
||||
@@ -28,10 +34,14 @@ export class ModelResolver {
|
||||
const lastDeployHash = await ctx.deployService.getLastDeployment(
|
||||
project.id,
|
||||
);
|
||||
|
||||
const inProgressDeployment =
|
||||
await ctx.deployService.getInProgressDeployment(project.id);
|
||||
if (inProgressDeployment) {
|
||||
return { status: SyncStatusEnum.IN_PROGRESS };
|
||||
}
|
||||
return currentHash == lastDeployHash
|
||||
? { isSyncronized: true }
|
||||
: { isSyncronized: false };
|
||||
? { status: SyncStatusEnum.SYNCRONIZED }
|
||||
: { status: SyncStatusEnum.UNSYNCRONIZED };
|
||||
}
|
||||
|
||||
public async deploy(
|
||||
|
||||
@@ -14,6 +14,12 @@ export const typeDefs = gql`
|
||||
MUSIC
|
||||
}
|
||||
|
||||
enum SyncStatus {
|
||||
IN_PROGRESS
|
||||
SYNCRONIZED
|
||||
UNSYNCRONIZED
|
||||
}
|
||||
|
||||
type DataSource {
|
||||
type: DataSourceName!
|
||||
properties: JSON!
|
||||
@@ -204,7 +210,7 @@ export const typeDefs = gql`
|
||||
}
|
||||
|
||||
type ModelSyncResponse {
|
||||
isSyncronized: Boolean!
|
||||
status: SyncStatus!
|
||||
}
|
||||
|
||||
type Diagram {
|
||||
|
||||
@@ -30,6 +30,7 @@ export interface MDLSyncResponse {
|
||||
export interface IDeployService {
|
||||
deploy(manifest: Manifest, projectId: number): Promise<DeployResponse>;
|
||||
getLastDeployment(projectId: number): Promise<string>;
|
||||
getInProgressDeployment(projectId: number): Promise<Deploy>;
|
||||
createMDLHash(manifest: Manifest): string;
|
||||
}
|
||||
|
||||
@@ -61,12 +62,19 @@ export class DeployService implements IDeployService {
|
||||
return lastDeploy.hash;
|
||||
}
|
||||
|
||||
public async getInProgressDeployment(projectId) {
|
||||
return await this.deployLogRepository.findInProgressProjectDeployLog(
|
||||
projectId,
|
||||
);
|
||||
}
|
||||
|
||||
public async deploy(manifest, projectId) {
|
||||
// generate hash of manifest
|
||||
const hash = this.createMDLHash(manifest);
|
||||
logger.debug(`Deploying model, hash: ${hash}`);
|
||||
logger.debug(manifest);
|
||||
// check if the model has been deployed
|
||||
|
||||
// check if the model current deployment
|
||||
const lastDeploy =
|
||||
await this.deployLogRepository.findLastProjectDeployLog(projectId);
|
||||
if (lastDeploy && lastDeploy.hash === hash) {
|
||||
@@ -74,7 +82,12 @@ export class DeployService implements IDeployService {
|
||||
return { status: DeployStatusEnum.SUCCESS };
|
||||
}
|
||||
|
||||
const deployData = { manifest, hash, projectId } as Deploy;
|
||||
const deployData = {
|
||||
manifest,
|
||||
hash,
|
||||
projectId,
|
||||
status: DeployStatusEnum.IN_PROGRESS,
|
||||
} as Deploy;
|
||||
const deploy = await this.deployLogRepository.createOne(deployData);
|
||||
|
||||
// deploy to wren-engine & AI-service
|
||||
|
||||
Reference in New Issue
Block a user