index.js
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.XxlJobExecutor = void 0;
const executor_1 = require("./executor");
/**
* XxlJobExecutor
*/
class XxlJobExecutor {
executor;
registryInterval;
/**
* 创建 XxlJobExecutor 实例
* @param {Map<String, Function>} jobHandlers 所有的任务执行函数,key: 任务标识,即调度中心任务配置的JobHandler;value: 任务执行函数
* @param {Object} context 为所有任务执行函数指定公共的上下文对象,常见比如数据库实例 { database, redis }
*/
constructor(opts, jobHandlers, context = undefined) {
const { XXL_JOB_EXECUTOR_KEY: executorKey, XXL_JOB_SCHEDULE_CENTER_URL: scheduleCenterUrl, XXL_JOB_ACCESS_TOKEN: accessToken, XXL_JOB_JOB_LOG_PATH: jobLogPath, } = opts;
this.executor = new executor_1.Executor(executorKey, scheduleCenterUrl, accessToken, jobLogPath, jobHandlers, context);
}
/**
* 应用执行器组件
* @param {Object} args
* @param {any} args.app 执行器server, express
* @param {string} args.appDomain 执行器 server 地址
*/
applyMiddleware({ app, domain }) {
this.executor.applyMiddleware({ app, domain });
const registry = this.executor.registry.bind(this.executor);
registry() && (this.registryInterval = setInterval(registry, 30000));
}
/**
* 关闭服务前应调用该方法,将执行器从调度中心摘除
*/
async close() {
if (this.registryInterval) {
clearInterval(this.registryInterval);
}
return this.executor.registryRemove();
}
}
exports.XxlJobExecutor = XxlJobExecutor;
//# sourceMappingURL=index.js.map