feat: 抽象定时任务
This commit is contained in:
parent
7d90bd368e
commit
4c109a006f
30
index.ts
30
index.ts
@ -1,30 +1,10 @@
|
|||||||
import { scheduleJob } from "node-schedule";
|
|
||||||
import managePipeline from "./controllers/managePipeLine";
|
|
||||||
import manageProject from "./controllers/manageProject";
|
|
||||||
import manageUser from "./controllers/manageUser";
|
|
||||||
import manageRobot from "./controllers/manageRobot";
|
import manageRobot from "./controllers/manageRobot";
|
||||||
|
import initSchedule from "./schedule";
|
||||||
|
|
||||||
const main = async () => {
|
// 启动定时任务
|
||||||
const fullProjList = await manageProject.getFullProjList();
|
initSchedule();
|
||||||
const fullPipelineList = await Promise.all(
|
|
||||||
fullProjList.map((v) => managePipeline.getFullPipelineList(v))
|
|
||||||
);
|
|
||||||
const fullUserMap = await manageUser.getFullUserMap(fullPipelineList);
|
|
||||||
const fullProjectMap = await manageProject.getFullProjectMap(fullProjList);
|
|
||||||
await managePipeline.insertFullPipelineList(
|
|
||||||
fullPipelineList,
|
|
||||||
fullUserMap,
|
|
||||||
fullProjectMap
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
main();
|
const server = Bun.serve({
|
||||||
|
|
||||||
scheduleJob("*/15 * * * *", main);
|
|
||||||
|
|
||||||
scheduleJob("0 10 * * 5", manageRobot.sendCIReportByCron);
|
|
||||||
|
|
||||||
Bun.serve({
|
|
||||||
async fetch(req) {
|
async fetch(req) {
|
||||||
const url = new URL(req.url);
|
const url = new URL(req.url);
|
||||||
if (url.pathname === "/ci") {
|
if (url.pathname === "/ci") {
|
||||||
@ -43,3 +23,5 @@ Bun.serve({
|
|||||||
},
|
},
|
||||||
port: 3000,
|
port: 3000,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log(`Listening on ${server.hostname}:${server.port}`);
|
14
schedule/index.ts
Normal file
14
schedule/index.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import { scheduleJob } from "node-schedule";
|
||||||
|
import manageRobot from "../controllers/manageRobot";
|
||||||
|
import syncPipLine from "./syncPipLine";
|
||||||
|
|
||||||
|
const initSchedule = async () => {
|
||||||
|
// 每天十点钟发送CI报告
|
||||||
|
scheduleJob("0 10 * * *", manageRobot.sendCIReportByCron);
|
||||||
|
// 每15分钟同步一次CI数据
|
||||||
|
scheduleJob("*/15 * * * *", syncPipLine);
|
||||||
|
// 立即同步一次
|
||||||
|
syncPipLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
export default initSchedule;
|
19
schedule/syncPipLine.ts
Normal file
19
schedule/syncPipLine.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import managePipeline from "../controllers/managePipeLine";
|
||||||
|
import manageProject from "../controllers/manageProject";
|
||||||
|
import manageUser from "../controllers/manageUser";
|
||||||
|
|
||||||
|
const syncPipLine = async () => {
|
||||||
|
const fullProjList = await manageProject.getFullProjList();
|
||||||
|
const fullPipelineList = await Promise.all(
|
||||||
|
fullProjList.map((v) => managePipeline.getFullPipelineList(v))
|
||||||
|
);
|
||||||
|
const fullUserMap = await manageUser.getFullUserMap(fullPipelineList);
|
||||||
|
const fullProjectMap = await manageProject.getFullProjectMap(fullProjList);
|
||||||
|
await managePipeline.insertFullPipelineList(
|
||||||
|
fullPipelineList,
|
||||||
|
fullUserMap,
|
||||||
|
fullProjectMap
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default syncPipLine;
|
Loading…
x
Reference in New Issue
Block a user