-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Allen Zhang (张涛)
committed
Jan 16, 2024
1 parent
62a438d
commit 01ad262
Showing
4 changed files
with
221 additions
and
14 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
packages/canyon-backend/src/tasks/services/cleaning-up-outdated-data.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Cron } from '@nestjs/schedule'; | ||
import { PrismaService } from '../../prisma/prisma.service'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { deleteSpecificCoverageData } from '../../adapter/coverage-data.adapter'; | ||
|
||
@Injectable() | ||
export class CleaningUpOutdatedDataService { | ||
constructor(private readonly prisma: PrismaService) {} | ||
// 每过一天清理一下coverage集合,删除超过3天的normal数据 | ||
@Cron('30 2 * * *') // 每天凌晨2点半执行 | ||
async cleaningUpOutdatedData() { | ||
const conditions = { | ||
where: { | ||
covType: 'normal', | ||
createdAt: { | ||
lt: new Date(new Date().valueOf() - 3 * 24 * 60 * 60 * 1000), | ||
}, | ||
}, | ||
}; | ||
|
||
const willDelCoverages = await this.prisma.coverage.findMany(conditions); | ||
|
||
const coverageDeleteManyRes = | ||
await this.prisma.coverage.deleteMany(conditions); | ||
|
||
const ids = willDelCoverages.map(({ relationID }) => relationID); | ||
|
||
for (let i = 0; i < ids.length; i++) { | ||
await deleteSpecificCoverageData(ids[i]); | ||
} | ||
|
||
console.log(coverageDeleteManyRes, 'coverageDeleteManyRes'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
packages/canyon-backend/src/tasks/services/pull-change-code-and-insert-db.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { diffLine } from '../../utils/diffline'; | ||
|
||
export class PullChangeCodeAndInsertDbService { | ||
async invoke(projectID, commitSha, compareTarget, accessToken, prisma) { | ||
const codechanges = await prisma.codechange.findMany({ | ||
where: { | ||
projectID, | ||
commitSha, | ||
compareTarget, | ||
}, | ||
}); | ||
if (codechanges.length === 0) { | ||
const diffLineData = await diffLine({ | ||
repoID: projectID, | ||
baseCommitSha: compareTarget, | ||
compareCommitSha: commitSha, | ||
token: accessToken, | ||
gitlabUrl: process.env.GITLAB_URL, | ||
}); | ||
const data = diffLineData.map(({ path, additions, deletions }) => { | ||
return { | ||
projectID, | ||
commitSha, | ||
compareTarget, | ||
path, | ||
additions, | ||
deletions, | ||
}; | ||
}); | ||
|
||
await prisma.codechange.createMany({ | ||
data: data, | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters