Compare commits

...

11 Commits

Author SHA1 Message Date
xiaojunnuo
ed01ef1eb7 v1.23.0 2024-08-05 18:08:44 +08:00
xiaojunnuo
7ec2218c9f fix: 修复环境变量多个下划线不生效的bug 2024-08-05 17:47:56 +08:00
xiaojunnuo
e8ed97206b feat: use node 20 2024-08-05 16:27:01 +08:00
xiaojunnuo
c45d85e612 chore: 2024-08-05 16:24:16 +08:00
xiaojunnuo
b3ff0fd880 chore: 2024-08-05 16:19:28 +08:00
xiaojunnuo
2fbc7459e2 build: trigger build image 2024-08-05 16:10:45 +08:00
xiaojunnuo
fbf4959463 v1.22.9 2024-08-05 16:10:39 +08:00
xiaojunnuo
02bb0be06a chore: 2024-08-05 16:07:28 +08:00
xiaojunnuo
87e440ee2a perf: 优化定时任务 2024-08-05 16:00:04 +08:00
xiaojunnuo
2182dce07c chore: 修复pipelineid为空被注册任务 2024-08-05 15:08:24 +08:00
xiaojunnuo
3f0a10007c build: trigger build image 2024-08-05 13:20:09 +08:00
17 changed files with 149 additions and 47 deletions

View File

@@ -3,6 +3,22 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [1.23.0](https://github.com/certd/certd/compare/v1.22.9...v1.23.0) (2024-08-05)
### Bug Fixes
* 修复环境变量多个下划线不生效的bug ([7ec2218](https://github.com/certd/certd/commit/7ec2218c9fee5bee2bf0aa31f3e3a4301575f247))
### Features
* use node 20 ([e8ed972](https://github.com/certd/certd/commit/e8ed97206bf28e83f942db2ef4ea07fa76fd3567))
## [1.22.9](https://github.com/certd/certd/compare/v1.22.8...v1.22.9) (2024-08-05)
### Performance Improvements
* 优化定时任务 ([87e440e](https://github.com/certd/certd/commit/87e440ee2a8b10dc571ce619f28bc83c1e5eb147))
## [1.22.8](https://github.com/certd/certd/compare/v1.22.7...v1.22.8) (2024-08-05)
### Performance Improvements

View File

@@ -22,7 +22,7 @@ CertD 是一个免费全自动申请和自动部署更新SSL证书的工具。
https://certd.handsfree.work/
> 注意数据将不定期清理,生产使用请自行部署
> 注意数据将不定期清理,不定期停止定时任务,生产使用请自行部署
> 包含敏感信息,务必自己本地部署进行生产使用
## 三、使用教程

View File

@@ -1 +1 @@
22:33
16:10

View File

@@ -9,5 +9,5 @@
}
},
"npmClient": "pnpm",
"version": "1.22.8"
"version": "1.23.0"
}

View File

@@ -1,4 +1,4 @@
FROM node:18-alpine AS builder
FROM node:20-alpine AS builder
EXPOSE 7001
WORKDIR /workspace/
COPY . /workspace/
@@ -9,7 +9,7 @@ RUN cp /workspace/certd-client/dist/* /workspace/certd-server/public/ -rf
RUN cd /workspace/certd-server && pnpm install && npm run build-on-docker
FROM node:18-alpine
FROM node:20-alpine
WORKDIR /app/
COPY --from=builder /workspace/certd-server/ /app/
RUN chmod +x /app/tools/linux/*

View File

@@ -3,6 +3,18 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [1.23.0](https://github.com/certd/certd/compare/v1.22.9...v1.23.0) (2024-08-05)
### Features
* use node 20 ([e8ed972](https://github.com/certd/certd/commit/e8ed97206bf28e83f942db2ef4ea07fa76fd3567))
## [1.22.9](https://github.com/certd/certd/compare/v1.22.8...v1.22.9) (2024-08-05)
### Performance Improvements
* 优化定时任务 ([87e440e](https://github.com/certd/certd/commit/87e440ee2a8b10dc571ce619f28bc83c1e5eb147))
## [1.22.8](https://github.com/certd/certd/compare/v1.22.7...v1.22.8) (2024-08-05)
### Performance Improvements

View File

@@ -1,6 +1,6 @@
{
"name": "@certd/ui-client",
"version": "1.22.8",
"version": "1.23.0",
"private": true,
"scripts": {
"dev": "vite --open",
@@ -24,10 +24,10 @@
"dependencies": {
"@ant-design/colors": "^7.0.2",
"@ant-design/icons-vue": "^7.0.1",
"@fast-crud/fast-crud": "^1.21.1",
"@fast-crud/fast-extends": "^1.21.1",
"@fast-crud/ui-antdv4": "^1.21.1",
"@fast-crud/ui-interface": "^1.21.1",
"@fast-crud/fast-crud": "^1.21.2",
"@fast-crud/fast-extends": "^1.21.2",
"@fast-crud/ui-antdv4": "^1.21.2",
"@fast-crud/ui-interface": "^1.21.2",
"@iconify/vue": "^4.1.1",
"@soerenmartius/vue3-clipboard": "^0.1.2",
"ant-design-vue": "^4.1.2",

View File

@@ -187,6 +187,9 @@ export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOp
title: "ID",
key: "id",
type: "number",
search: {
show: true
},
column: {
width: 50
},
@@ -233,6 +236,31 @@ export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOp
}
}
},
content: {
title: "定时任务数量",
type: "number",
column: {
cellRender({ value }) {
if (value && value.triggers) {
return value.triggers?.length > 0 ? value.triggers.length : "-";
}
return "-";
}
},
valueBuilder({ row }) {
if (row.content) {
row.content = JSON.parse(row.content);
}
},
valueResolve({ row }) {
if (row.content) {
row.content = JSON.stringify(row.content);
}
},
form: {
show: false
}
},
lastVars: {
title: "到期剩余",
type: "number",
@@ -328,6 +356,9 @@ export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOp
sorter: true,
align: "center",
width: 80
},
form: {
value: 0
}
},
createTime: {

View File

@@ -13,3 +13,4 @@ typeorm:
username: postgres
password: root
database: postgres

View File

@@ -3,6 +3,18 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [1.23.0](https://github.com/certd/certd/compare/v1.22.9...v1.23.0) (2024-08-05)
### Bug Fixes
* 修复环境变量多个下划线不生效的bug ([7ec2218](https://github.com/certd/certd/commit/7ec2218c9fee5bee2bf0aa31f3e3a4301575f247))
## [1.22.9](https://github.com/certd/certd/compare/v1.22.8...v1.22.9) (2024-08-05)
### Performance Improvements
* 优化定时任务 ([87e440e](https://github.com/certd/certd/commit/87e440ee2a8b10dc571ce619f28bc83c1e5eb147))
## [1.22.8](https://github.com/certd/certd/compare/v1.22.7...v1.22.8) (2024-08-05)
### Performance Improvements

View File

@@ -1,6 +1,6 @@
{
"name": "@certd/ui-server",
"version": "1.22.8",
"version": "1.23.0",
"description": "fast-server base midway",
"private": true,
"type": "module",

View File

@@ -12,7 +12,7 @@ function parseEnv(defaultConfig: any) {
continue;
}
keyName = keyName.replace('certd_', '');
const configKey = keyName.replace('_', '.');
const configKey = keyName.replaceAll('_', '.');
const oldValue = _.get(defaultConfig, configKey);
let value: any = process.env[key];
if (typeof oldValue === 'boolean') {

View File

@@ -73,6 +73,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
const info = await this.info(pipelineId);
if (info && !info.disabled) {
const pipeline = JSON.parse(info.content);
// 手动触发不要await
this.registerTriggers(pipeline);
}
}
@@ -87,15 +88,16 @@ export class PipelineService extends BaseService<PipelineEntity> {
}
async update(bean: PipelineEntity) {
await this.clearTriggers(bean.id);
//更新非trigger部分
await super.update(bean);
await this.registerTriggerById(bean.id);
}
async save(bean: PipelineEntity) {
await this.clearTriggers(bean.id);
const pipeline = JSON.parse(bean.content);
bean.title = pipeline.title;
if (bean.content) {
const pipeline = JSON.parse(bean.content);
bean.title = pipeline.title;
}
await this.addOrUpdate(bean);
await this.registerTriggerById(bean.id);
}
@@ -173,7 +175,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
if (immediateTriggerOnce) {
await this.trigger(pipeline.id);
await sleep(1000);
await sleep(200);
}
}
@@ -224,6 +226,11 @@ export class PipelineService extends BaseService<PipelineEntity> {
}
registerCron(pipelineId, trigger) {
if (pipelineId == null) {
logger.warn('pipelineId为空无法注册定时任务');
return;
}
let cron = trigger.props?.cron;
if (cron == null) {
return;
@@ -232,15 +239,20 @@ export class PipelineService extends BaseService<PipelineEntity> {
if (cron.startsWith('*')) {
cron = '0' + cron.substring(1, cron.length);
}
const name = this.buildCronKey(pipelineId, trigger.id);
const triggerId = trigger.id;
const name = this.buildCronKey(pipelineId, triggerId);
this.cron.remove(name);
this.cron.register({
name,
cron,
job: async () => {
logger.info('定时任务触发:', pipelineId, trigger.id);
logger.info('定时任务触发:', pipelineId, triggerId);
if (pipelineId == null) {
logger.warn('pipelineId为空,无法执行');
return;
}
try {
await this.run(pipelineId, trigger.id);
await this.run(pipelineId, triggerId);
} catch (e) {
logger.error('定时job执行失败', e);
}

View File

@@ -22,6 +22,7 @@ export class CronConfiguration {
...this.config,
});
container.registerObject('cron', this.cron);
this.cron.start();
this.logger.info('cron started');
}
}

View File

@@ -17,56 +17,63 @@ export class CronTask {
name: string;
stoped = false;
timeoutId: any;
nextTime: any;
constructor(req: CronTaskReq, logger: ILogger) {
this.cron = req.cron;
this.job = req.job;
this.name = req.name;
this.logger = logger;
this.start();
this.genNextTime();
}
start() {
genNextTime() {
if (!this.cron) {
return;
return null;
}
if (this.stoped) {
return;
return null;
}
const interval = parser.parseExpression(this.cron);
const next = interval.next().getTime();
const now = Date.now();
const delay = next - now;
this.timeoutId = setTimeout(async () => {
try {
if (this.stoped) {
return;
}
await this.job();
} catch (e) {
this.logger.error(`[cron] job error : [${this.name}]`, e);
}
this.start();
}, delay);
this.logger.info(`[cron] [${this.name}], cron:${this.cron}, next run :${new Date(next).toLocaleString()}`);
this.nextTime = next;
return next;
}
stop() {
this.stoped = true;
clearTimeout(this.timeoutId);
}
}
export class Cron {
logger: ILogger;
immediateTriggerOnce: boolean;
bucket: Record<string, CronTask> = {};
queue: CronTask[] = [];
constructor(opts: any) {
this.logger = opts.logger;
this.immediateTriggerOnce = opts.immediateTriggerOnce;
}
start() {
this.logger.info('[cron] start');
this.queue.forEach(task => {
task.genNextTime();
});
setInterval(() => {
const now = new Date().getTime();
for (const task of this.queue) {
if (task.nextTime <= now) {
task.job().catch(e => {
this.logger.error(`job execute error : [${task.name}]`, e);
});
task.genNextTime();
}
}
}, 1000 * 60);
}
register(req: CronTaskReq) {
if (!req.cron) {
this.logger.info(`[cron] register once : [${req.name}]`);
@@ -78,21 +85,22 @@ export class Cron {
this.logger.info(`[cron] register cron : [${req.name}] ,${req.cron}`);
const task = new CronTask(req, this.logger);
this.bucket[task.name] = task;
this.queue.push(task);
this.logger.info('当前定时任务数量:', this.getTaskSize());
}
remove(taskName: string) {
this.logger.info(`[cron] remove : [${taskName}]`);
const task = this.bucket[taskName];
if (task) {
task.stop();
delete this.bucket[taskName];
const index = this.queue.findIndex(item => item.name === taskName);
if (index !== -1) {
this.queue[index].stop();
this.queue.splice(index, 1);
}
this.logger.info('当前定时任务数量:', this.getTaskSize());
}
getTaskSize() {
const tasks = Object.keys(this.bucket);
const tasks = Object.keys(this.queue);
return tasks.length;
}
}

View File

@@ -75,6 +75,10 @@ export class AsyncSsh2Client {
}
async exec(script: string) {
if (!script) {
this.logger.info('script 为空,取消执行');
return;
}
return new Promise((resolve, reject) => {
this.logger.info(`执行命令:[${this.connConf.host}][exec]: ` + script);
this.conn.exec(script, (err: Error, stream: any) => {
@@ -97,6 +101,10 @@ export class AsyncSsh2Client {
data += out;
this.logger.info(`[${this.connConf.host}][info]: ` + out.trimEnd());
})
.on('error', (err: any) => {
reject(err);
this.logger.error(err);
})
.stderr.on('data', (ret: Buffer) => {
const err = this.convert(ret);
data += err;

View File

@@ -30,6 +30,7 @@ export class HostShellExecutePlugin extends AbstractTaskPlugin {
name: 'a-textarea',
vModel: 'value',
},
required: true,
})
script!: string;