mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-01 04:40:38 +08:00
Add cron task management to QLAPI (#2826)
* Initial plan * Add cron management capabilities to QLAPI - Added GetCrons, GetCronById, EnableCrons, DisableCrons, RunCrons to proto - Implemented gRPC handlers for new cron operations - Updated client.js to expose new methods to scripts - Updated sample to demonstrate new API usage Co-authored-by: whyour <22700758+whyour@users.noreply.github.com> * Add documentation for QLAPI cron management features Co-authored-by: whyour <22700758+whyour@users.noreply.github.com> * Specify pnpm version 8.3.1 in package.json Add packageManager field to enforce pnpm@8.3.1 as requested Co-authored-by: whyour <22700758+whyour@users.noreply.github.com> * Revert pnpm-lock.yaml to original state The lockfile was inadvertently updated during dependency installation for proto generation. Reverting to maintain consistency with pnpm@8.3.1. Co-authored-by: whyour <22700758+whyour@users.noreply.github.com> * Regenerate proto files with correct tool versions Regenerated using protoc v3.17.3 and protoc-gen-ts_proto v2.6.1 to match the original project configuration. Co-authored-by: whyour <22700758+whyour@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: whyour <22700758+whyour@users.noreply.github.com>
This commit is contained in:
@@ -30,6 +30,12 @@ import {
|
||||
UpdateCronRequest,
|
||||
DeleteCronsRequest,
|
||||
CronResponse,
|
||||
GetCronsRequest,
|
||||
CronsResponse,
|
||||
GetCronByIdRequest,
|
||||
EnableCronsRequest,
|
||||
DisableCronsRequest,
|
||||
RunCronsRequest,
|
||||
} from '../protos/api';
|
||||
import { NotificationInfo } from '../data/notify';
|
||||
|
||||
@@ -323,3 +329,116 @@ export const deleteCrons = async (
|
||||
callback(e);
|
||||
}
|
||||
};
|
||||
|
||||
export const getCrons = async (
|
||||
call: ServerUnaryCall<GetCronsRequest, CronsResponse>,
|
||||
callback: sendUnaryData<CronsResponse>,
|
||||
) => {
|
||||
try {
|
||||
const cronService = Container.get(CronService);
|
||||
const result = await cronService.crontabs({
|
||||
searchValue: call.request.searchValue || '',
|
||||
page: '0',
|
||||
size: '0',
|
||||
sorter: '',
|
||||
filters: '',
|
||||
queryString: '',
|
||||
});
|
||||
const data = result.data.map((x) => normalizeCronData(x as CronItem));
|
||||
callback(null, {
|
||||
code: 200,
|
||||
data: data.filter((x): x is CronItem => x !== undefined),
|
||||
});
|
||||
} catch (e: any) {
|
||||
callback(null, {
|
||||
code: 500,
|
||||
data: [],
|
||||
message: e.message,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const getCronById = async (
|
||||
call: ServerUnaryCall<GetCronByIdRequest, CronResponse>,
|
||||
callback: sendUnaryData<CronResponse>,
|
||||
) => {
|
||||
try {
|
||||
if (!call.request.id) {
|
||||
return callback(null, {
|
||||
code: 400,
|
||||
data: undefined,
|
||||
message: 'id parameter is required',
|
||||
});
|
||||
}
|
||||
|
||||
const cronService = Container.get(CronService);
|
||||
const data = (await cronService.getDb({ id: call.request.id })) as CronItem;
|
||||
callback(null, { code: 200, data: normalizeCronData(data) });
|
||||
} catch (e: any) {
|
||||
callback(null, {
|
||||
code: 404,
|
||||
data: undefined,
|
||||
message: e.message,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const enableCrons = async (
|
||||
call: ServerUnaryCall<EnableCronsRequest, Response>,
|
||||
callback: sendUnaryData<Response>,
|
||||
) => {
|
||||
try {
|
||||
if (!call.request.ids || call.request.ids.length === 0) {
|
||||
return callback(null, {
|
||||
code: 400,
|
||||
message: 'ids parameter is required',
|
||||
});
|
||||
}
|
||||
|
||||
const cronService = Container.get(CronService);
|
||||
await cronService.enabled(call.request.ids);
|
||||
callback(null, { code: 200 });
|
||||
} catch (e: any) {
|
||||
callback(e);
|
||||
}
|
||||
};
|
||||
|
||||
export const disableCrons = async (
|
||||
call: ServerUnaryCall<DisableCronsRequest, Response>,
|
||||
callback: sendUnaryData<Response>,
|
||||
) => {
|
||||
try {
|
||||
if (!call.request.ids || call.request.ids.length === 0) {
|
||||
return callback(null, {
|
||||
code: 400,
|
||||
message: 'ids parameter is required',
|
||||
});
|
||||
}
|
||||
|
||||
const cronService = Container.get(CronService);
|
||||
await cronService.disabled(call.request.ids);
|
||||
callback(null, { code: 200 });
|
||||
} catch (e: any) {
|
||||
callback(e);
|
||||
}
|
||||
};
|
||||
|
||||
export const runCrons = async (
|
||||
call: ServerUnaryCall<RunCronsRequest, Response>,
|
||||
callback: sendUnaryData<Response>,
|
||||
) => {
|
||||
try {
|
||||
if (!call.request.ids || call.request.ids.length === 0) {
|
||||
return callback(null, {
|
||||
code: 400,
|
||||
message: 'ids parameter is required',
|
||||
});
|
||||
}
|
||||
|
||||
const cronService = Container.get(CronService);
|
||||
await cronService.run(call.request.ids);
|
||||
callback(null, { code: 200 });
|
||||
} catch (e: any) {
|
||||
callback(e);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user