bc-schedule-server
Advanced tools
Comparing version 1.1.2 to 1.1.3
import Koa from 'koa'; | ||
import Router from 'koa-router'; | ||
import { IBcScheduleType, ITaskList } from './types'; | ||
import { IBcScheduleType, ITaskList, ITaskOption } from './types'; | ||
export declare class BcScheduleServer { | ||
@@ -10,6 +10,7 @@ app: Koa; | ||
private taskCacheList; | ||
private taskOption?; | ||
private options; | ||
private logInstance; | ||
constructor(options: IBcScheduleType); | ||
registerTask(list: ITaskList): string[]; | ||
registerTask(list: ITaskList, option?: ITaskOption): string[]; | ||
private start; | ||
@@ -16,0 +17,0 @@ private expendAndMiddleware; |
@@ -36,8 +36,11 @@ 'use strict'; | ||
this.runningTaskList = new Set(); | ||
this.taskOption = { excludeJobId: [] }; | ||
this.logInstance = new logger.WLogger(this.options.logOption || {}); | ||
this.start(); | ||
} | ||
registerTask(list) { | ||
registerTask(list, option) { | ||
if (!util.isArray(list)) | ||
return this.taskList; | ||
if (util.isObject(option)) | ||
this.taskOption = option; | ||
if (this.taskCacheList) { | ||
@@ -101,4 +104,14 @@ for (const task of list) { | ||
} | ||
hasTask(jobId) { | ||
return this.runningTaskList.has(jobId); | ||
hasTask(jobId, executorHandler) { | ||
var _a, _b, _c; | ||
let result = this.runningTaskList.has(jobId); | ||
if (executorHandler) { | ||
if (typeof ((_a = this.taskOption) === null || _a === void 0 ? void 0 : _a.excludeJobId) === 'boolean' && this.taskOption.excludeJobId) { | ||
result = false; | ||
} | ||
else if (util.isArray((_b = this.taskOption) === null || _b === void 0 ? void 0 : _b.excludeJobId) && ((_c = this.taskOption) === null || _c === void 0 ? void 0 : _c.excludeJobId).includes(executorHandler)) { | ||
result = false; | ||
} | ||
} | ||
return result; | ||
} | ||
@@ -113,3 +126,3 @@ taskCheck(ctx, next) { | ||
} | ||
else if (this.hasTask(jobId)) { | ||
else if (this.hasTask(jobId, executorHandler)) { | ||
ctx.status = 200; | ||
@@ -116,0 +129,0 @@ ctx.body = { code: 500, msg: `jobId:${jobId} is running` }; |
@@ -39,2 +39,5 @@ import { LeveledLogMethod } from 'winston'; | ||
export declare type ITaskList = ITaskItem[]; | ||
export declare type ITaskOption = { | ||
excludeJobId?: true | string[]; | ||
}; | ||
export interface IReadLogType { | ||
@@ -41,0 +44,0 @@ logId: number; |
{ | ||
"name": "bc-schedule-server", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "xxl-job koa server", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -11,2 +11,3 @@ # bc-schedule-server | ||
- 默认按照 logs/YYYY-MM-DD/logId.log 目录结构存储 | ||
- 支持跳过执行任务限制 | ||
- 暂不支持任务超时配置及单次任务的终止动作 | ||
@@ -70,2 +71,3 @@ | ||
``` | ||
// BcScheduleServer 配置 | ||
{ | ||
@@ -81,2 +83,6 @@ port: number, // 服务监听端口 | ||
} | ||
// registerTask 配置 | ||
schedule.registerTask([...tasks], { | ||
excludeJobId: true | string[] // 配置 true 所有任务都不加执行限制;string[] 只对配置了的任务明跳过限制 | ||
}) | ||
@@ -83,0 +89,0 @@ // 基本使用方式 |
26859
471
131