mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2024-11-01 14:10:29 +08:00
任务调用支持多参数
This commit is contained in:
parent
73fb586797
commit
4ce452cb76
@ -4,16 +4,16 @@
|
||||
"id": 1,
|
||||
"jobId": null,
|
||||
"repeatConf": "{\"count\":1,\"type\":1,\"limit\":5,\"name\":\"每秒执行,总共5次\",\"taskType\":1,\"every\":1000,\"service\":\"taskDemoService.test()\",\"status\":1,\"id\":1,\"createTime\":\"2021-03-10 14:25:13\",\"updateTime\":\"2021-03-10 14:25:13\",\"jobId\":1}",
|
||||
"name": "每秒执行,总共5次",
|
||||
"name": "每秒执行一次",
|
||||
"cron": null,
|
||||
"limit": 5,
|
||||
"limit": null,
|
||||
"every": 1000,
|
||||
"remark": null,
|
||||
"status": 0,
|
||||
"startDate": null,
|
||||
"endDate": null,
|
||||
"data": null,
|
||||
"service": "taskDemoService.test()",
|
||||
"service": "taskDemoService.test(1,2)",
|
||||
"type": 1,
|
||||
"nextRunTime": "2021-3-10 14:25:18",
|
||||
"taskType": 1
|
||||
|
@ -12,8 +12,8 @@ export class TaskDemoService extends BaseService {
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
async test() {
|
||||
this.logger.info('我被调用了');
|
||||
async test(a, b) {
|
||||
this.logger.info('我被调用了', a, b);
|
||||
return '任务执行成功';
|
||||
}
|
||||
}
|
||||
|
@ -332,14 +332,27 @@ export class TaskInfoService extends BaseService {
|
||||
const service = await this.app
|
||||
.getApplicationContext()
|
||||
.getAsync(_.lowerFirst(arr[0]));
|
||||
for (const child of arr) {
|
||||
|
||||
for (let i = 1; i < arr.length; i++) {
|
||||
const child = arr[i];
|
||||
if (child.includes('(')) {
|
||||
const lastArr = child.split('(');
|
||||
const param = lastArr[1].replace(')', '');
|
||||
if (!param) {
|
||||
return service[lastArr[0]]();
|
||||
const [methodName, paramsStr] = child.split('(');
|
||||
const params = paramsStr
|
||||
.replace(')', '')
|
||||
.split(',')
|
||||
.map(param => param.trim());
|
||||
|
||||
if (params.length === 1 && params[0] === '') {
|
||||
return service[methodName]();
|
||||
} else {
|
||||
return service[lastArr[0]](JSON.parse(param));
|
||||
const parsedParams = params.map(param => {
|
||||
try {
|
||||
return JSON.parse(param);
|
||||
} catch (e) {
|
||||
return param; // 如果不是有效的JSON,则返回原始字符串
|
||||
}
|
||||
});
|
||||
return service[methodName](...parsedParams);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user