Skip to content

Commit

Permalink
feat: adjustment delay
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Zhang (张涛) committed Apr 10, 2024
1 parent 0c3b46f commit 0a2c196
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/canyon-backend/src/coverage/coverage.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { join } from 'path';
import { download } from '../utils/download';
import { PrismaService } from '../prisma/prisma.service';
import { ConsumerCoverageService } from './services/consumer-coverage.service';
import { TestCoverage } from './services/test.coverage';
// import axios from 'axios';
// import * as platform from 'platform'
// export function getPlatformInfo(str) {
Expand All @@ -37,8 +38,10 @@ export class CoverageController {
private readonly retrieveCoverageTreeSummaryService: RetrieveCoverageTreeSummaryService,
private prisma: PrismaService,
private consumerCoverageService: ConsumerCoverageService,
private testCoverage: TestCoverage,
) {
this.consumerCoverageService.invoke();
// this.testCoverage.invoke();
}

@UseGuards(JwtAuthGuard)
Expand Down
2 changes: 2 additions & 0 deletions packages/canyon-backend/src/coverage/coverage.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { CoverageLog, CoverageLogSchema } from './schemas/coverage-log.schema';
import { TypeOrmModule } from '@nestjs/typeorm';
import { CoveragediskEntity } from './coveragedisk.entity';
import { CoveragediskService } from './services/coveragedisk.service';
import { TestCoverage } from './services/test.coverage';

@Module({
imports: [
Expand Down Expand Up @@ -43,6 +44,7 @@ import { CoveragediskService } from './services/coveragedisk.service';
ConsumerCoverageService,
PullChangeCodeAndInsertDbService,
CoveragediskService,
TestCoverage,
],
})
export class CoverageModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class ConsumerCoverageService {
const lockName = `${_lockName}_${queueDataToBeConsumed.projectID}_${queueDataToBeConsumed.sha}`;

const now = new Date();
const timeout = 1000 * 60 * 1; // 1分钟
const timeout = 1000 * 60 * 5; // 1分钟
const expirationTime = new Date(now.getTime() + timeout);

const existingLock = await this.prisma.distributedlock.findUnique({
Expand Down Expand Up @@ -73,7 +73,7 @@ export class ConsumerCoverageService {
} else {
// 被锁住了就push到队列尾部
await this.coveragediskService.pushQueue(queueDataToBeConsumed);
await sleep(1000);
await sleep(3000);
// return false;
}
} else {
Expand All @@ -100,11 +100,11 @@ export class ConsumerCoverageService {
}
} else {
// 空闲等待1s,防止cpu占用过高
await sleep(1000);
await sleep(3000);
}
} catch (e) {
console.log(e);
await sleep(1000);
await sleep(3000);
}
}
}
Expand Down
48 changes: 48 additions & 0 deletions packages/canyon-backend/src/coverage/services/test.coverage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Injectable } from '@nestjs/common';
import { PrismaService } from '../../prisma/prisma.service';
import { CoverageDataAdapterService } from './coverage-data-adapter.service';
import { PullChangeCodeAndInsertDbService } from './pull-change-code-and-insert-db.service';
import { CoveragediskService } from './coveragedisk.service';
import {
genSummaryMapByCoverageMap,
getSummaryByPath,
mergeCoverageMap,
} from '@canyon/data';

@Injectable()
export class TestCoverage {
constructor(
private readonly prisma: PrismaService,
private readonly coverageDataAdapterService: CoverageDataAdapterService,
private readonly pullChangeCodeAndInsertDbService: PullChangeCodeAndInsertDbService,
private readonly coveragediskService: CoveragediskService,
) {}

async invoke() {
const coverages = await this.prisma.coverage.findMany({
where: {
sha: 'b61375c962499fe448a7985b22c9c7f6b1f023ea',
covType: 'agg',
},
});
let cov = {};
for (let i = 0; i < coverages.length; i++) {
console.log(i);
const c = await this.coverageDataAdapterService.retrieve(
coverages[i].relationID,
);
cov = mergeCoverageMap(cov, c);
console.log(
coverages[i].reportID,
getSummaryByPath('~', genSummaryMapByCoverageMap(c, []))['statements'][
'pct'
],
);
}
console.log(
getSummaryByPath('~', genSummaryMapByCoverageMap(cov, []))['statements'][
'pct'
],
);
}
}

0 comments on commit 0a2c196

Please sign in to comment.