Skip to content

Commit

Permalink
feat: upd
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Zhang (张涛) committed Apr 10, 2024
1 parent e0c5b8d commit d3bcded
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 85 deletions.
8 changes: 1 addition & 7 deletions packages/canyon-backend/gen/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@ function capitalizeFirstLetter(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}


// 定义模版name
const name = 'usage';

const arr = [
'model',
'module',
'resolver',
'service'
];
const arr = ['model', 'module', 'resolver', 'service'];
for (let i = 0; i < arr.length; i++) {
try {
const a = arr[i];
Expand Down
8 changes: 1 addition & 7 deletions packages/canyon-backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,24 @@ import { AppService } from './app.service';
import { ConfigModule } from '@nestjs/config';
import { PrismaModule } from './prisma/prisma.module';
import { CoverageModule } from './coverage/coverage.module';
// import { TasksModule } from './tasks/tasks.module';
import { ScheduleModule } from '@nestjs/schedule';
import { AuthModule } from './auth/auth.module';
import { UserModule } from './user/user.module';
import { GraphQLModule } from '@nestjs/graphql';
import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo';
import { ProjectModule } from './project/project.module';
// import { TasksModule } from './tasks/tasks.module';
import { CodechangeModule } from './codechange/codechange.module';
import { SourcecodeController } from './sourcecode/sourcecode.controller';
import { SourcecodeService } from './sourcecode/sourcecode.service';
import { SourcecodeModule } from './sourcecode/sourcecode.module';
import { join } from 'path';
import { ServeStaticModule } from '@nestjs/serve-static';
import { UploadModule } from './upload/upload.module';
// import { OrganizationModule } from './organization/organization.module';
// import { UsageModule } from './usage/usage.module';
import { CoveragedataModule } from './coveragedata/coveragedata.module';
import { MongooseModule } from '@nestjs/mongoose';
import { TypeOrmModule } from '@nestjs/typeorm';
import { CoveragediskEntity } from './coverage/coveragedisk.entity';
// const condition = process.env.MODE === 'task';

@Module({
imports: [
MongooseModule.forRoot(process.env.MONGODB_URL),
Expand All @@ -45,8 +41,6 @@ import { CoveragediskEntity } from './coverage/coveragedisk.entity';
CodechangeModule,
SourcecodeModule,
UploadModule,
// OrganizationModule,
// UsageModule,
ServeStaticModule.forRoot({
rootPath: join(__dirname, '../../canyon-platform', 'dist'),
exclude: ['/graphql/(.*)'],
Expand Down
5 changes: 2 additions & 3 deletions packages/canyon-backend/src/common/models/page-info.model.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Field, ID, ObjectType } from '@nestjs/graphql';
import { ObjectType } from '@nestjs/graphql';

// total、pageSize、current
@ObjectType()
export class PageInfoModel {
}
export class PageInfoModel {}
6 changes: 2 additions & 4 deletions packages/canyon-backend/src/coverage/coverage.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Module } from '@nestjs/common';
// import { AppService } from './app.service';
import { RetrieveCoverageTreeSummaryService } from './services/retrieve-coverage-tree-summary.service';
import { CoverageClientService } from './services/coverage-client.service';
import { PrismaService } from '../prisma/prisma.service';
Expand All @@ -16,7 +15,7 @@ import { PullChangeCodeAndInsertDbService } from './services/pull-change-code-an
import { CoverageLog, CoverageLogSchema } from './schemas/coverage-log.schema';
import { TypeOrmModule } from '@nestjs/typeorm';
import { CoveragediskEntity } from './coveragedisk.entity';
import { MenuService } from './services/menu.service';
import { CoveragediskService } from './services/coveragedisk.service';

@Module({
imports: [
Expand All @@ -36,15 +35,14 @@ import { MenuService } from './services/menu.service';
],
controllers: [CoverageController],
providers: [
// AppService,
PrismaService,
CoverageClientService,
RetrieveCoverageTreeSummaryService,
CoverageService,
CoverageDataAdapterService,
ConsumerCoverageService,
PullChangeCodeAndInsertDbService,
MenuService,
CoveragediskService,
],
})
export class CoverageModule {}
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { Injectable } from '@nestjs/common';
import { PrismaService } from '../../prisma/prisma.service';
// import {
// getQueueWithSameShaAndProjectID,
// pushQueue,
// } from '../../queues/coverage';
import {
genSummaryMapByCoverageMap,
getSummaryByPath,
Expand All @@ -14,7 +10,7 @@ import { validateObject } from '../../utils/coverage';
import { CoverageDataAdapterService } from './coverage-data-adapter.service';
import { PullChangeCodeAndInsertDbService } from './pull-change-code-and-insert-db.service';
import { logger } from '../../logger';
import { MenuService } from './menu.service';
import { CoveragediskService } from './coveragedisk.service';

const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

Expand All @@ -24,15 +20,15 @@ export class ConsumerCoverageService {
private readonly prisma: PrismaService,
private readonly coverageDataAdapterService: CoverageDataAdapterService,
private readonly pullChangeCodeAndInsertDbService: PullChangeCodeAndInsertDbService,
private readonly menuService: MenuService,
private readonly coveragediskService: CoveragediskService,
) {}

async invoke() {
while (true) {
try {
// 获取将要消费的队列数据,sha和projectID相同,并且已经聚合
const queueDataToBeConsumed =
await this.menuService.getQueueWithSameShaAndProjectID();
await this.coveragediskService.getQueueWithSameShaAndProjectID();
// 如果存在
if (queueDataToBeConsumed) {
const _lockName = 'consumer_coverage';
Expand Down Expand Up @@ -76,7 +72,7 @@ export class ConsumerCoverageService {
});
} else {
// 被锁住了就push到队列尾部
await this.menuService.pushQueue(queueDataToBeConsumed);
await this.coveragediskService.pushQueue(queueDataToBeConsumed);
// return false;
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ import {
UnauthorizedException,
} from '@nestjs/common';
import { PrismaService } from '../../prisma/prisma.service';
// import { createNewCoverageData } from '../../adapter/coverage-data.adapter';
import { CoverageClientDto } from '../dto/coverage-client.dto';
import { formatReportObject } from '../../utils/coverage';
import { Coverage } from '@prisma/client';
import { pushQueue } from '../../queues/coverage';
import { InjectModel } from '@nestjs/mongoose';
// import { CoverageData } from '../schemas/coverage-data.schema';
import { Model } from 'mongoose';
import { CoverageLog } from '../schemas/coverage-log.schema';
import { MenuService } from './menu.service';
import { CoveragediskService } from './coveragedisk.service';
/**
* 上传覆盖率,十分重要的服务
*/
Expand All @@ -35,7 +32,7 @@ export class CoverageClientService {
private readonly prisma: PrismaService,
@InjectModel(CoverageLog.name)
private coverageLogModel: Model<CoverageLog>,
private menuService: MenuService,
private coveragediskService: CoveragediskService,
) {}

async invoke(currentUser, coverageClientDto: CoverageClientDto, ip) {
Expand Down Expand Up @@ -118,7 +115,7 @@ export class CoverageClientService {
ip,
},
});
await this.menuService.pushQueue(cov);
await this.coveragediskService.pushQueue(cov);
return {
msg: 'ok',
coverageId: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { Repository } from 'typeorm';
import { mergeCoverageMap } from '@canyon/data';

@Injectable()
export class MenuService {
export class CoveragediskService {
constructor(
@InjectRepository(CoveragediskEntity)
private readonly menuRepository: Repository<CoveragediskEntity>,
private readonly coveragediskRepository: Repository<CoveragediskEntity>,
) {}
async pushQueue(data) {
return this.menuRepository.insert({
return this.coveragediskRepository.insert({
pid: String(process.pid),
projectID: data.projectID,
sha: data.sha,
Expand All @@ -20,7 +20,7 @@ export class MenuService {
});
}
async getQueueWithSameShaAndProjectID() {
const old = await this.menuRepository.findOne({
const old = await this.coveragediskRepository.findOne({
where: {
pid: String(process.pid),
},
Expand All @@ -37,7 +37,7 @@ export class MenuService {
if (!old) {
return false;
}
const arr = await this.menuRepository.find({
const coveragedisks = await this.coveragediskRepository.find({
where: {
projectID: old.projectID,
sha: old.sha,
Expand All @@ -48,13 +48,13 @@ export class MenuService {
},
});
let cov = {};
for (let i = 0; i < arr.length; i++) {
const toBeConsumedQueues = await this.menuRepository.findOne({
where: { id: arr[i].id, pid: String(process.pid) },
for (let i = 0; i < coveragedisks.length; i++) {
const toBeConsumedQueues = await this.coveragediskRepository.findOne({
where: { id: coveragedisks[i].id, pid: String(process.pid) },
});
// 聚合
cov = mergeCoverageMap(cov, JSON.parse(toBeConsumedQueues.data).coverage);
await this.menuRepository.delete({ id: arr[i].id });
await this.coveragediskRepository.delete({ id: coveragedisks[i].id });
}
return {
...JSON.parse(old.data),
Expand Down
41 changes: 0 additions & 41 deletions packages/canyon-backend/src/queues/coverage.ts

This file was deleted.

0 comments on commit d3bcded

Please sign in to comment.