"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.XxlJobExecutor = void 0;
const executor_1 = require("./executor");
class XxlJobExecutor {
    executor;
    registryInterval;
    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);
    }
    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