build: trident-sync prepare

This commit is contained in:
xiaojunnuo
2023-01-29 13:44:19 +08:00
parent dcd1023a39
commit 07a45b4530
589 changed files with 36886 additions and 2 deletions
@@ -0,0 +1,27 @@
import { Config, Configuration, Logger } from '@midwayjs/decorator';
import { ILogger } from '@midwayjs/logger';
import { IMidwayContainer } from '@midwayjs/core';
import { Cron } from './cron';
// ... (see below) ...
@Configuration({
namespace: 'cron',
//importConfigs: [join(__dirname, './config')],
})
export class CronConfiguration {
@Config()
config;
@Logger()
logger: ILogger;
cron: Cron;
async onReady(container: IMidwayContainer) {
this.logger.info('cron start');
this.cron = new Cron({
logger: this.logger,
...this.config,
});
container.registerObject('cron', this.cron);
this.logger.info('cron started');
}
}
@@ -0,0 +1,38 @@
import cron from 'node-cron';
export type CronTask = {
/**
* 为空则为单次执行
*/
cron: string;
job: () => Promise<void>;
name: string;
};
export class Cron {
logger;
constructor(opts) {
this.logger = opts.logger;
}
register(task: CronTask) {
if (!task.cron) {
this.logger.info(`[cron] register once : [${task.name}]`);
task.job();
return;
}
this.logger.info(`[cron] register cron : [${task.name}] ,${task.cron}`);
cron.schedule(task.cron, task.job, {
name: task.name,
});
}
remove(taskName: string) {
this.logger.info(`[cron] remove : [${taskName}]`);
const tasks = cron.getTasks() as Map<any, any>;
tasks.delete(taskName);
}
getList() {
const tasks = cron.getTasks();
return tasks.size;
}
}
@@ -0,0 +1,5 @@
// src/index.ts
export { CronConfiguration as Configuration } from './configuration';
// export * from './controller/user';
// export * from './controller/api';
// export * from './service/user';
@@ -0,0 +1,6 @@
// src/index.ts
import '@certd/plugin-all';
export { PipelineConfiguration as Configuration } from '@certd/pipeline';
// export * from './controller/user';
// export * from './controller/api';
// export * from './service/user';
@@ -0,0 +1,27 @@
import { ILogger } from "@midwayjs/logger";
import { ITaskPlugin,Autowire, IsTaskPlugin, TaskInput } from "@certd/pipeline";
@IsTaskPlugin({
name: "EchoPlugin",
title: "测试插件",
desc: "test",
})
export class EchoPlugin implements ITaskPlugin {
@TaskInput({
title: "测试属性",
component: {
name: "text",
},
})
test?: string;
@Autowire()
// @ts-ignore
logger: ILogger;
async onInit(){}
async execute(): Promise<void> {
return Promise.resolve(undefined);
}
}