Skip to content

Commit

Permalink
Merge pull request #3 from DTStack/for-github
Browse files Browse the repository at this point in the history
For GitHub
  • Loading branch information
liuxy0551 authored Jul 16, 2024
2 parents be6b21e + a6925f8 commit 9f11c0c
Show file tree
Hide file tree
Showing 30 changed files with 187 additions and 156 deletions.
3 changes: 0 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ DEPLOY.md
.env.*

# 检测结果
**/yice-report/*.html
**/yice-report/**/*.html

# compiled output
dist
node_modules

# OS
Expand Down
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/dist/**
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ node_modules
!.vscode/extensions.json

# 检测结果
**/yice-report/*.html
**/yice-report/**/*.html

yice-performance*.tar.gz
Expand Down
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
before_script:
- echo $CI_COMMIT_REF_NAME
- whoami
- pnpm i --reporter=silent
- pnpm install --reporter=silent

stages:
- prettier
Expand Down
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,38 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [2.1.2](///compare/v2.1.1...v2.1.2) (2024-07-16)


### Features

* log optimize 6fbdd17

### [2.1.1](///compare/v2.1.0...v2.1.1) (2024-07-16)


### Features

* console log optimize b5d1edc
* week data email optimize 373488b


### Bug Fixes

* send email when email not saved d9e8e17

## [2.1.0](///compare/v2.0.2...v2.1.0) (2024-07-15)


### Features

* log optimize c182fcb


### Bug Fixes

* sendAll need fileSizeChartData 1eb96df

### [2.0.2](///compare/v2.0.1...v2.0.2) (2024-07-12)


Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cd yice-performance

### 服务启动

- 安装服务依赖:`pnpm i`
- 安装服务依赖:`pnpm install`
- 运行 node 服务和前端页面:`pnpm dev`

> 服务配置项 `.env` 文件中的属性按实际填写即可,建议本地新建一个 `.env.local` 文件,配置一些较隐私的内容,这个文件不会被 git 感知且配置项的优先级大于 `.env` 文件。
Expand Down
5 changes: 1 addition & 4 deletions apps/server/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
"name": "yice-performance",
"name": "yice-performance-server",
"version": "1.0.0",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"scripts": {
"dev": "NODE_ENV=development nest start --watch",
"build": "NODE_ENV=production nest build",
Expand Down
7 changes: 2 additions & 5 deletions apps/server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import * as compression from 'compression';

import { HttpExceptionFilter } from './filters/http-exception.filter';
import { AppModule } from './app.module';
import { formatDate } from './utils';
const packageJson = require('../package.json');

const APP_PORT = process.env.APP_PORT || 4000;
Expand Down Expand Up @@ -34,11 +33,9 @@ async function bootstrap() {

await app.listen(APP_PORT, () => {
console.log(
`${formatDate()} app is running in mode ${
process.env.NODE_ENV
} on http://localhost:${APP_PORT}`
`app is running in mode [${process.env.NODE_ENV}] on http://localhost:${APP_PORT}`
);
console.log(`${formatDate()} api docs: http://localhost:${APP_PORT}/docs`);
console.log(`api docs: http://localhost:${APP_PORT}/docs`);
});
}

Expand Down
32 changes: 20 additions & 12 deletions apps/server/src/modules/build/services/build.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,27 @@ export class BuildService {
throw new HttpException('repository, branch 不符合规则,此次数据不录入', HttpStatus.OK);
}

const version = branch.split('_')?.filter((item) => item.includes('.x'))?.[0];
try {
const version = branch.split('_')?.filter((item) => item.includes('.x'))?.[0];

const { projectId } = await this.projectRepository.findOneBy(getWhere({ appName }));
const { projectId } = await this.projectRepository.findOneBy(getWhere({ appName }));

const build = this.buildRepository.create({
projectId,
repository,
branch,
version,
duration,
fileSize,
});
const result = await this.buildRepository.save(build);
return result;
const build = this.buildRepository.create({
projectId,
repository,
branch,
version,
duration,
fileSize,
});
const result = await this.buildRepository.save(build);
return result;
} catch (error) {
console.log(
`\n构建数据未保存, appName: ${appName}, repository: ${repository}, branch: ${branch}, duration: ${duration}, fileSize: ${fileSize}`,
error
);
throw new HttpException('构建数据未保存', HttpStatus.OK);
}
}
}
3 changes: 3 additions & 0 deletions apps/server/src/modules/devops/services/devops.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class DevopsService {
});
return res?.data?.data;
} catch (error) {
console.log(`请求 devops 接口失败, DEVOPS_COOKIE: ${process.env.DEVOPS_COOKIE}`);
throw new HttpException('请求 devops 接口失败', HttpStatus.OK);
}
}
Expand Down Expand Up @@ -86,6 +87,7 @@ export class DevopsService {
const history = await this.getHistory(histories?.[0]?.id);
return history;
} catch (error) {
console.log(`请求 devops 接口失败, DEVOPS_COOKIE: ${process.env.DEVOPS_COOKIE}`);
throw new HttpException('请求 devops 接口失败', HttpStatus.OK);
}
}
Expand All @@ -96,6 +98,7 @@ export class DevopsService {
const result = await this.axiosGet(`http://devops.dtstack.cn/api/v1/projects`);
return result;
} catch (error) {
console.log(`请求 devops 接口失败, DEVOPS_COOKIE: ${process.env.DEVOPS_COOKIE}`);
throw new HttpException('请求 devops 接口失败', HttpStatus.OK);
}
}
Expand Down
51 changes: 31 additions & 20 deletions apps/server/src/modules/email/controllers/email.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ApiOperation } from '@nestjs/swagger';

import { ChartService } from '@/modules/chart/services/chart.service';
import { ProjectService } from '@/modules/project/services/project.service';
import { formatDate, lastMonthRange, lastWeekRange } from '@/utils';
import { lastMonthRange, lastWeekRange } from '@/utils';
import { EmailService } from '../services/email.service';

@Controller('email')
Expand Down Expand Up @@ -36,18 +36,20 @@ export class EmailController {
try {
await this.sendProject({ projectId, emails });
} catch (error) {}
console.log(formatDate(), ` ${name}, 定时发送单个子产品的数据周报到指定邮箱`);
console.log(
`\nprojectId: ${projectId}, ${name}, 发送【单个子产品】的数据周报到指定邮箱`
);
}
});
}
async handleSendAll() {
if (process.env.DEFAULT_EMAIL) {
this.sendAll({ emails: process.env.DEFAULT_EMAIL });
console.log(formatDate(), ' 定时发送所有子产品的数据周报到指定邮箱');
console.log('\n发送【所有子产品】的数据周报到指定邮箱');
await this.sendAll({ emails: process.env.DEFAULT_EMAIL });
}
}

@ApiOperation({ summary: '发送邮件' })
@ApiOperation({ summary: '发送【单个子产品】的数据周报到指定邮箱' })
@HttpCode(HttpStatus.OK)
@Post('sendProjectMail')
async sendProject(@Body() { projectId, emails: _emails }) {
Expand All @@ -56,10 +58,10 @@ export class EmailController {

if (emails?.split(',')?.length) {
try {
const result = await this.generatePromise(project);
const result = await this.generatePromise({ ...project, emails });
return result;
} catch (error) {
console.log(formatDate(), ' 邮件数据处理失败', error);
console.log(`\nprojectId: ${projectId}, ${project?.name}, 邮件数据处理失败`, error);
throw new HttpException('没有历史检测数据', HttpStatus.OK);
}
}
Expand All @@ -82,7 +84,6 @@ export class EmailController {
if (projectChartData?.versionNameList?.length) {
const result = await this.emailService.sendMail(
project,
lastWeekRange,
projectChartData,
fileSizeChartData
);
Expand All @@ -92,7 +93,7 @@ export class EmailController {
}
}

@ApiOperation({ summary: '定时发送所有子产品的数据周报到指定邮箱' })
@ApiOperation({ summary: '发送【所有子产品】的数据周报到指定邮箱' })
@HttpCode(HttpStatus.OK)
@Post('sendAll')
async sendAll(@Body() { emails = process.env.DEFAULT_EMAIL }) {
Expand All @@ -102,40 +103,50 @@ export class EmailController {
}

const [startTime, endTime] = lastWeekRange;
const [startMonthTime, endMonthTime] = lastMonthRange;
let projectList = await this.projectService.findAll();
projectList = projectList.filter((project) => project.name !== '汇总');

const promiseList = projectList.map((project) => {
const projectChartDataPromiseList = projectList.map((project) => {
return this.chartService.projectChart({
projectId: project.projectId,
startTime,
endTime,
});
});
const fileSizeChartPromiseList = projectList.map((project) => {
return this.chartService.fileSizeChart({
projectId: project.projectId,
startTime: startMonthTime,
endTime: endMonthTime,
});
});

const chartDataList = [];
const projectChartDataResults = await Promise.all(projectChartDataPromiseList);
const fileSizeChartDataResults = await Promise.all(fileSizeChartPromiseList);

const projectChartDataList = [];
const projectChartDataResults = await Promise.all(promiseList);
for (let i = 0; i < projectChartDataResults.length; i++) {
if (projectChartDataResults[i].versionNameList?.length) {
const { projectId, name } = projectList[i];
projectChartDataList.push({
chartDataList.push({
projectId,
name,
projectChartData: projectChartDataResults[i],
fileSizeChartData: fileSizeChartDataResults[i],
});
}
}

if (projectChartDataList.length) {
const result = await this.emailService.sendMailAllProject(
emails,
projectChartDataList,
lastWeekRange
);
if (chartDataList.length) {
const result = await this.emailService.sendMailAllProject(emails, chartDataList);
return result;
}
} catch (error) {
throw new HttpException(`尝试发送所有子产品的数据周报失败, ${error}`, HttpStatus.OK);
throw new HttpException(
`尝试发送【所有子产品】的数据周报失败, ${error}`,
HttpStatus.OK
);
}
}
}
24 changes: 15 additions & 9 deletions apps/server/src/modules/email/services/email.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { MailerService } from '@nestjs-modules/mailer';
import { IFileSizeChartData, IProjectChartData } from 'typing';

import { formatDate } from '@/utils';
import { lastWeekRange } from '@/utils';
import { renderChart } from '@/utils/echarts';

@Injectable()
Expand All @@ -11,7 +11,6 @@ export class EmailService {

async sendMail(
project,
lastWeekRange,
projectChartData: IProjectChartData,
fileSizeChartData: IFileSizeChartData
) {
Expand All @@ -26,32 +25,39 @@ export class EmailService {
subject: `【${name}】易测数据周报(${startTime}~${endTime})`, // 标题
html,
});
console.log(formatDate(), ' 发送单个子产品的数据周报成功', result);
console.log(
`\nprojectId: ${projectId}, ${name}, 发送【单个子产品】的数据周报成功`,
result
);
return result;
} catch (error) {
console.log(formatDate(), ' 尝试发送单个子产品的数据周报失败', error);
console.log(
`\nprojectId: ${projectId}, ${name}, 尝试发送【单个子产品】的数据周报失败`,
error
);
throw new HttpException('尝试发送单个子产品的数据周报失败', HttpStatus.OK);
}
}
}

// 定时发送所有子产品的数据周报到指定邮箱
async sendMailAllProject(emails, projectChartDataList = [], lastWeekRange) {
async sendMailAllProject(emails, chartDataList = []) {
const [_, __, startTime, endTime] = lastWeekRange;

if (emails?.split(',')?.length) {
const html = renderChart(projectChartDataList);
const html = renderChart(chartDataList);
try {
const result = await this.mailerService.sendMail({
to: emails?.split(','),
subject: `【数栈子产品】易测数据周报(${startTime}~${endTime})`, // 标题
html,
});
console.log(formatDate(), ' 发送所有子产品的数据周报成功', result);

console.log('\n发送【所有子产品】的数据周报成功', result);
return result;
} catch (error) {
console.log(formatDate(), ' 尝试发送所有子产品的数据周报失败', error);
throw new HttpException('尝试发送所有子产品的数据周报失败', HttpStatus.OK);
console.log('\n尝试发送【所有子产品】的数据周报失败', error);
throw new HttpException('尝试发送【所有子产品】的数据周报失败', HttpStatus.OK);
}
}
}
Expand Down
Loading

0 comments on commit 9f11c0c

Please sign in to comment.