mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-01 04:40:38 +08:00
更新 ts-proto 版本
This commit is contained in:
@@ -10,7 +10,7 @@ const addCron = (
|
||||
callback: sendUnaryData<AddCronResponse>,
|
||||
) => {
|
||||
for (const item of call.request.crons) {
|
||||
const { id, schedule, command, extraSchedules, name } = item;
|
||||
const { id, schedule, command, extra_schedules, name } = item;
|
||||
if (scheduleStacks.has(id)) {
|
||||
scheduleStacks.get(id)?.forEach((x) => x.cancel());
|
||||
}
|
||||
@@ -23,8 +23,8 @@ const addCron = (
|
||||
command,
|
||||
);
|
||||
|
||||
if (extraSchedules?.length) {
|
||||
extraSchedules.forEach((x) => {
|
||||
if (extra_schedules?.length) {
|
||||
extra_schedules.forEach((x) => {
|
||||
Logger.info(
|
||||
'[schedule][创建定时任务], 任务ID: %s, 名称: %s, cron: %s, 执行命令: %s',
|
||||
id,
|
||||
@@ -40,8 +40,8 @@ const addCron = (
|
||||
Logger.info(`[schedule][准备运行任务] 命令: ${command}`);
|
||||
runCron(command, item);
|
||||
}),
|
||||
...(extraSchedules?.length
|
||||
? extraSchedules.map((x) =>
|
||||
...(extra_schedules?.length
|
||||
? extra_schedules.map((x) =>
|
||||
nodeSchedule.scheduleJob(id, x.schedule, async () => {
|
||||
Logger.info(`[schedule][准备运行任务] 命令: ${command}`);
|
||||
runCron(command, item);
|
||||
|
||||
@@ -4,6 +4,7 @@ import EnvService from '../services/env';
|
||||
import { sendUnaryData, ServerUnaryCall } from '@grpc/grpc-js';
|
||||
import {
|
||||
CreateEnvRequest,
|
||||
CronItem,
|
||||
DeleteEnvsRequest,
|
||||
DisableEnvsRequest,
|
||||
EnableEnvsRequest,
|
||||
@@ -21,6 +22,15 @@ import {
|
||||
import LoggerInstance from '../loaders/logger';
|
||||
import pick from 'lodash/pick';
|
||||
import SystemService from '../services/system';
|
||||
import CronService from '../services/cron';
|
||||
import {
|
||||
CronDetailRequest,
|
||||
CronDetailResponse,
|
||||
CreateCronRequest,
|
||||
UpdateCronRequest,
|
||||
DeleteCronsRequest,
|
||||
CronResponse,
|
||||
} from '../protos/api';
|
||||
|
||||
Container.set('logger', LoggerInstance);
|
||||
|
||||
@@ -171,3 +181,58 @@ export const systemNotify = async (
|
||||
callback(e);
|
||||
}
|
||||
};
|
||||
|
||||
export const getCronDetail = async (
|
||||
call: ServerUnaryCall<CronDetailRequest, CronDetailResponse>,
|
||||
callback: sendUnaryData<CronDetailResponse>,
|
||||
) => {
|
||||
try {
|
||||
const cronService = Container.get(CronService);
|
||||
const data = (await cronService.find({
|
||||
log_path: call.request.log_path,
|
||||
})) as CronItem;
|
||||
console.log('data', data);
|
||||
callback(null, { code: 200, data: data || undefined });
|
||||
} catch (e: any) {
|
||||
callback(e);
|
||||
}
|
||||
};
|
||||
|
||||
export const createCron = async (
|
||||
call: ServerUnaryCall<CreateCronRequest, CronResponse>,
|
||||
callback: sendUnaryData<CronResponse>,
|
||||
) => {
|
||||
try {
|
||||
const cronService = Container.get(CronService);
|
||||
const data = (await cronService.create(call.request)) as CronItem;
|
||||
callback(null, { code: 200, data });
|
||||
} catch (e: any) {
|
||||
callback(e);
|
||||
}
|
||||
};
|
||||
|
||||
export const updateCron = async (
|
||||
call: ServerUnaryCall<UpdateCronRequest, CronResponse>,
|
||||
callback: sendUnaryData<CronResponse>,
|
||||
) => {
|
||||
try {
|
||||
const cronService = Container.get(CronService);
|
||||
const data = (await cronService.update(call.request)) as CronItem;
|
||||
callback(null, { code: 200, data });
|
||||
} catch (e: any) {
|
||||
callback(e);
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteCrons = async (
|
||||
call: ServerUnaryCall<DeleteCronsRequest, Response>,
|
||||
callback: sendUnaryData<Response>,
|
||||
) => {
|
||||
try {
|
||||
const cronService = Container.get(CronService);
|
||||
await cronService.remove(call.request.ids);
|
||||
callback(null, { code: 200 });
|
||||
} catch (e: any) {
|
||||
callback(e);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user