@whyour/qinglong 2.22.0 → 2.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/back/protos/cron.proto +4 -0
- package/docs/development/node-cron-migration.md +49 -0
- package/docs/development/task-startup.md +78 -0
- package/docs/releases/2.22.0.md +8 -0
- package/docs/releases/2.23.0.md +33 -0
- package/docs/script-history.md +53 -0
- package/package.json +9 -8
- package/scripts/benchmark-script-history.cjs +39 -0
- package/scripts/publish-static.sh +34 -0
- package/scripts/sync-static.sh +20 -0
- package/scripts/wait-for-mirror.sh +214 -0
- package/shell/api.sh +56 -70
- package/shell/node_path_cache.sh +10 -2
- package/shell/otask.sh +7 -9
- package/shell/preload/sitecustomize.js +6 -2
- package/shell/preload/sitecustomize.py +4 -2
- package/shell/share.sh +1 -1
- package/shell/task-timeout.sh +63 -0
- package/shell/task.sh +8 -6
- package/shell/update.sh +40 -95
- package/shell/upgrade.cjs +8 -0
- package/static/build/api/config.js +2 -6
- package/static/build/api/env.js +15 -14
- package/static/build/api/open.js +2 -1
- package/static/build/api/script.js +155 -9
- package/static/build/api/subscription.js +3 -6
- package/static/build/api/system.js +35 -3
- package/static/build/config/grpcCerts.js +89 -40
- package/static/build/config/subscription.js +19 -11
- package/static/build/config/util.js +6 -4
- package/static/build/loaders/express.js +2 -0
- package/static/build/loaders/initData.js +20 -30
- package/static/build/loaders/initTask.js +11 -1
- package/static/build/middlewares/uniqueConstraintError.js +15 -0
- package/static/build/protos/cron.js +63 -2
- package/static/build/schedule/addCron.js +45 -63
- package/static/build/schedule/client.js +19 -1
- package/static/build/schedule/delCron.js +1 -1
- package/static/build/schedule/setConcurrency.js +27 -0
- package/static/build/services/config.js +2 -3
- package/static/build/services/cron.js +36 -10
- package/static/build/services/env.js +1 -1
- package/static/build/services/grpc.js +2 -1
- package/static/build/services/log.js +1 -1
- package/static/build/services/open.js +106 -31
- package/static/build/services/schedule.js +20 -10
- package/static/build/services/script.js +1 -1
- package/static/build/services/scriptHistory.js +30 -0
- package/static/build/services/sshKey.js +39 -14
- package/static/build/services/subscription.js +104 -53
- package/static/build/services/system.js +67 -32
- package/static/build/services/user.js +15 -10
- package/static/build/shared/cronCommand.js +17 -0
- package/static/build/shared/cronSchedule.js +101 -0
- package/static/build/shared/cronScheduler.js +73 -0
- package/static/build/shared/i18n.js +3 -2
- package/static/build/shared/logPath.js +15 -0
- package/static/build/shared/loginThrottle.js +45 -0
- package/static/build/shared/pLimit.js +19 -6
- package/static/build/shared/runCron.js +13 -4
- package/static/build/shared/scriptHistory.js +445 -0
- package/static/build/shared/shellQuote.js +11 -0
- package/static/build/shared/subscriptionMutationLock.js +34 -0
- package/static/build/shared/subscriptionPath.js +41 -0
- package/static/build/shared/subscriptionStorage.js +98 -0
- package/static/build/shared/utils.js +2 -1
- package/static/build/token.js +3 -14
- package/static/build/validation/schedule.js +3 -18
- package/static/dist/292.264757f0.async.js +1 -0
- package/static/dist/3512.95e41255.async.js +1 -0
- package/static/dist/index.html +2 -2
- package/static/dist/preload_helper.01fcd534.js +1 -0
- package/static/dist/src__pages__dependence__modal.0fa8b421.async.js +1 -0
- package/static/dist/src__pages__diff__index.b94e5dc5.async.js +1 -0
- package/static/dist/src__pages__script__editModal.afabf073.async.js +1 -0
- package/static/dist/src__pages__script__editNameModal.789ad87b.async.js +1 -0
- package/static/dist/src__pages__script__historyDrawer.8c58d958.async.js +1 -0
- package/static/dist/src__pages__script__historyDrawer.a449193a.chunk.css +1 -0
- package/static/dist/src__pages__script__index.ab360776.chunk.css +1 -0
- package/static/dist/src__pages__script__index.fc575945.async.js +1 -0
- package/static/dist/src__pages__script__saveModal.8fca1a22.async.js +1 -0
- package/static/dist/src__pages__script__saveWithHistory.99ece830.async.js +1 -0
- package/static/dist/src__pages__subscription__modal.30868ba8.async.js +1 -0
- package/static/dist/{umi.fc019050.js → umi.3a24a9fa.js} +1 -1
- package/test/back/advisory-input-security.test.cjs +416 -0
- package/test/back/code-scanning-security.test.cjs +189 -0
- package/test/back/cron-macros.test.cjs +51 -0
- package/test/back/cron-schedule-compatibility.test.cjs +69 -0
- package/test/back/cron-scheduler-routing.test.cjs +59 -0
- package/test/back/draft-path-security.test.cjs +235 -0
- package/test/back/env-import-security.test.cjs +91 -0
- package/test/back/execution-lifecycle.test.cjs +1 -1
- package/test/back/file-access-scope.test.cjs +180 -0
- package/test/back/grpc-mtls-security.test.cjs +136 -0
- package/test/back/http-security.test.cjs +105 -5
- package/test/back/legacy-cron-recovery.test.cjs +76 -0
- package/test/back/linux-mirror-result.test.cjs +176 -0
- package/test/back/listen-security.test.cjs +1 -0
- package/test/back/mirror-status.test.cjs +257 -0
- package/test/back/node-cron-migration.test.cjs +65 -0
- package/test/back/node-path-cache.test.cjs +29 -0
- package/test/back/node-path-lock.test.cjs +6 -2
- package/test/back/preload-lazy-notify.test.cjs +168 -0
- package/test/back/queued-cron-invalidation.test.cjs +98 -0
- package/test/back/restart-instance-recovery.test.cjs +116 -0
- package/test/back/scheduler-bulk-recovery.test.cjs +40 -0
- package/test/back/scheduler-concurrency.test.cjs +411 -0
- package/test/back/scheduler-reconciliation.test.cjs +58 -4
- package/test/back/script-file-access.test.cjs +210 -0
- package/test/back/script-history-api.test.cjs +551 -0
- package/test/back/script-history.test.cjs +383 -0
- package/test/back/shell-api-parsing.test.cjs +4 -4
- package/test/back/shell-translation-output.test.cjs +16 -0
- package/test/back/shell-upgrade.test.cjs +312 -0
- package/test/back/shellApiToken.test.cjs +151 -0
- package/test/back/ssh-config-home.test.cjs +113 -0
- package/test/back/static-mirror-trigger.test.cjs +441 -0
- package/test/back/static-mirror.test.cjs +179 -0
- package/test/back/stop-race.test.cjs +5 -1
- package/test/back/subscription-mutation-lock.test.cjs +83 -0
- package/test/back/subscription-review-regression.test.cjs +607 -0
- package/test/back/subscription-storage-regression.test.cjs +553 -0
- package/test/back/system-dependence-cache.test.cjs +1 -0
- package/test/back/system-export-history.test.cjs +119 -0
- package/test/back/systemTokenRenewal.test.cjs +497 -0
- package/test/back/task-shell-lifecycle.test.cjs +194 -0
- package/test/back/unique-constraint-error.test.cjs +72 -0
- package/test/back/upgrade-guards.test.cjs +285 -0
- package/test/back/upgrade-lifecycle.test.cjs +288 -0
- package/test/back/upgrade-transaction.test.cjs +133 -0
- package/test/back/user-security.test.cjs +102 -1
- package/test/back/wpush-grpc.test.cjs +1 -0
- package/test/fixtures/legacy-cron.json +1371 -0
- package/test/front/diff-file-routing.test.cjs +126 -0
- package/test/front/script-history-save.test.cjs +121 -0
- package/test/helpers/upgrade-fixture.cjs +30 -0
- package/version.yaml +14 -19
- package/static/dist/2096.6d98fd12.async.js +0 -1
- package/static/dist/4859.97d6653c.async.js +0 -1
- package/static/dist/6707.801b886b.async.js +0 -1
- package/static/dist/preload_helper.cf7de3fa.js +0 -1
- package/static/dist/src__pages__dependence__modal.a29c1a0f.async.js +0 -1
- package/static/dist/src__pages__diff__index.1714b941.async.js +0 -1
- package/static/dist/src__pages__script__editModal.22acdf7c.async.js +0 -1
- package/static/dist/src__pages__script__editNameModal.1a521cc0.async.js +0 -1
- package/static/dist/src__pages__script__index.60b6f827.chunk.css +0 -1
- package/static/dist/src__pages__script__index.a18b2692.async.js +0 -1
- package/static/dist/src__pages__script__saveModal.8965b74c.async.js +0 -1
- package/static/dist/src__pages__subscription__modal.38991e1e.async.js +0 -1
- /package/static/dist/{4859.1b962b29.chunk.css → 292.1b962b29.chunk.css} +0 -0
|
@@ -761,25 +761,27 @@ async function replaceDomainInFile(filePath, oldDomainWithScheme, newDomainWithS
|
|
|
761
761
|
}
|
|
762
762
|
async function _updateLinuxMirror(osType, mirrorDomainWithScheme) {
|
|
763
763
|
const S = (0, container_1.isInContainer)() ? 'sudo ' : '';
|
|
764
|
+
// APT otherwise returns zero when index downloads fail with transient errors.
|
|
765
|
+
const aptUpdate = `${S}apt-get update --error-on=any`;
|
|
764
766
|
let filePath, currentDomainWithScheme;
|
|
765
767
|
switch (osType) {
|
|
766
768
|
case 'Debian':
|
|
767
769
|
filePath = '/etc/apt/sources.list.d/debian.sources';
|
|
768
770
|
currentDomainWithScheme = await getCurrentMirrorDomain(filePath);
|
|
769
771
|
if (currentDomainWithScheme) {
|
|
770
|
-
return `${S}sed -i 's|${currentDomainWithScheme}|${mirrorDomainWithScheme || 'http://deb.debian.org'}|g' ${filePath} || (${S}mkdir -p /etc/apt/sources.list.d && echo -e "Types: deb\\nURIs: ${mirrorDomainWithScheme || 'http://deb.debian.org'}\\nSuites: \\$(grep VERSION_CODENAME /etc/os-release | cut -d= -f2) \\$(grep VERSION_CODENAME /etc/os-release | cut -d= -f2)-updates\\nComponents: main\\nSigned-By: /usr/share/keyrings/debian-archive-keyring.gpg" | ${S}tee ${filePath}) && ${
|
|
772
|
+
return `${S}sed -i 's|${currentDomainWithScheme}|${mirrorDomainWithScheme || 'http://deb.debian.org'}|g' ${filePath} || (${S}mkdir -p /etc/apt/sources.list.d && echo -e "Types: deb\\nURIs: ${mirrorDomainWithScheme || 'http://deb.debian.org'}\\nSuites: \\$(grep VERSION_CODENAME /etc/os-release | cut -d= -f2) \\$(grep VERSION_CODENAME /etc/os-release | cut -d= -f2)-updates\\nComponents: main\\nSigned-By: /usr/share/keyrings/debian-archive-keyring.gpg" | ${S}tee ${filePath}) && ${aptUpdate}`;
|
|
771
773
|
}
|
|
772
774
|
else {
|
|
773
|
-
return `${S}mkdir -p /etc/apt/sources.list.d && echo -e "Types: deb\\nURIs: ${mirrorDomainWithScheme || 'http://deb.debian.org'}\\nSuites: \\$(grep VERSION_CODENAME /etc/os-release | cut -d= -f2) \\$(grep VERSION_CODENAME /etc/os-release | cut -d= -f2)-updates\\nComponents: main\\nSigned-By: /usr/share/keyrings/debian-archive-keyring.gpg" | ${S}tee ${filePath} && ${
|
|
775
|
+
return `${S}mkdir -p /etc/apt/sources.list.d && echo -e "Types: deb\\nURIs: ${mirrorDomainWithScheme || 'http://deb.debian.org'}\\nSuites: \\$(grep VERSION_CODENAME /etc/os-release | cut -d= -f2) \\$(grep VERSION_CODENAME /etc/os-release | cut -d= -f2)-updates\\nComponents: main\\nSigned-By: /usr/share/keyrings/debian-archive-keyring.gpg" | ${S}tee ${filePath} && ${aptUpdate}`;
|
|
774
776
|
}
|
|
775
777
|
case 'Ubuntu':
|
|
776
778
|
filePath = '/etc/apt/sources.list.d/ubuntu.sources';
|
|
777
779
|
currentDomainWithScheme = await getCurrentMirrorDomain(filePath);
|
|
778
780
|
if (currentDomainWithScheme) {
|
|
779
|
-
return `${S}sed -i 's|${currentDomainWithScheme}|${mirrorDomainWithScheme || 'http://archive.ubuntu.com'}|g' ${filePath} || (${S}mkdir -p /etc/apt/sources.list.d && echo -e "Types: deb\\nURIs: ${mirrorDomainWithScheme || 'http://archive.ubuntu.com'}\\nSuites: \\$(grep VERSION_CODENAME /etc/os-release | cut -d= -f2) \\$(grep VERSION_CODENAME /etc/os-release | cut -d= -f2)-updates \\$(grep VERSION_CODENAME /etc/os-release | cut -d= -f2)-backports\\nComponents: main restricted universe multiverse\\nSigned-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg" | ${S}tee ${filePath}) && ${
|
|
781
|
+
return `${S}sed -i 's|${currentDomainWithScheme}|${mirrorDomainWithScheme || 'http://archive.ubuntu.com'}|g' ${filePath} || (${S}mkdir -p /etc/apt/sources.list.d && echo -e "Types: deb\\nURIs: ${mirrorDomainWithScheme || 'http://archive.ubuntu.com'}\\nSuites: \\$(grep VERSION_CODENAME /etc/os-release | cut -d= -f2) \\$(grep VERSION_CODENAME /etc/os-release | cut -d= -f2)-updates \\$(grep VERSION_CODENAME /etc/os-release | cut -d= -f2)-backports\\nComponents: main restricted universe multiverse\\nSigned-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg" | ${S}tee ${filePath}) && ${aptUpdate}`;
|
|
780
782
|
}
|
|
781
783
|
else {
|
|
782
|
-
return `${S}mkdir -p /etc/apt/sources.list.d && echo -e "Types: deb\\nURIs: ${mirrorDomainWithScheme || 'http://archive.ubuntu.com'}\\nSuites: \\$(grep VERSION_CODENAME /etc/os-release | cut -d= -f2) \\$(grep VERSION_CODENAME /etc/os-release | cut -d= -f2)-updates \\$(grep VERSION_CODENAME /etc/os-release | cut -d= -f2)-backports\\nComponents: main restricted universe multiverse\\nSigned-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg" | ${S}tee ${filePath} && ${
|
|
784
|
+
return `${S}mkdir -p /etc/apt/sources.list.d && echo -e "Types: deb\\nURIs: ${mirrorDomainWithScheme || 'http://archive.ubuntu.com'}\\nSuites: \\$(grep VERSION_CODENAME /etc/os-release | cut -d= -f2) \\$(grep VERSION_CODENAME /etc/os-release | cut -d= -f2)-updates \\$(grep VERSION_CODENAME /etc/os-release | cut -d= -f2)-backports\\nComponents: main restricted universe multiverse\\nSigned-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg" | ${S}tee ${filePath} && ${aptUpdate}`;
|
|
783
785
|
}
|
|
784
786
|
case 'Alpine':
|
|
785
787
|
filePath = '/etc/apk/repositories';
|
|
@@ -17,6 +17,7 @@ const store_1 = require("../shared/store");
|
|
|
17
17
|
const auth_1 = require("../shared/auth");
|
|
18
18
|
const path_1 = __importDefault(require("path"));
|
|
19
19
|
const i18n_1 = require("../shared/i18n");
|
|
20
|
+
const uniqueConstraintError_1 = __importDefault(require("../middlewares/uniqueConstraintError"));
|
|
20
21
|
const protectedPathCase_1 = __importDefault(require("../middlewares/protectedPathCase"));
|
|
21
22
|
function resolveTrustProxy(value = process.env.QL_TRUST_PROXY) {
|
|
22
23
|
const setting = value === null || value === void 0 ? void 0 : value.trim();
|
|
@@ -151,6 +152,7 @@ exports.default = ({ app }) => {
|
|
|
151
152
|
});
|
|
152
153
|
});
|
|
153
154
|
app.use((0, celebrate_1.errors)());
|
|
155
|
+
app.use(uniqueConstraintError_1.default);
|
|
154
156
|
app.use((err, req, res, next) => {
|
|
155
157
|
if (err.name === 'UnauthorizedError') {
|
|
156
158
|
return res
|
|
@@ -46,11 +46,10 @@ const open_1 = __importDefault(require("../services/open"));
|
|
|
46
46
|
const store_1 = require("../shared/store");
|
|
47
47
|
const logger_1 = __importDefault(require("./logger"));
|
|
48
48
|
const client_1 = __importDefault(require("../schedule/client"));
|
|
49
|
-
const open_2 = require("../data/open");
|
|
50
49
|
const runningInstance_1 = require("../data/runningInstance");
|
|
51
50
|
const i18n_1 = require("../shared/i18n");
|
|
52
51
|
exports.default = async () => {
|
|
53
|
-
var _a, _b, _c, _d, _e, _f, _g
|
|
52
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
54
53
|
const cronService = typedi_1.Container.get(cron_2.default);
|
|
55
54
|
const envService = typedi_1.Container.get(env_1.default);
|
|
56
55
|
const dependenceService = typedi_1.Container.get(dependence_1.default);
|
|
@@ -58,20 +57,7 @@ exports.default = async () => {
|
|
|
58
57
|
const userService = typedi_1.Container.get(user_1.default);
|
|
59
58
|
const openService = typedi_1.Container.get(open_1.default);
|
|
60
59
|
// 初始化增加系统配置
|
|
61
|
-
|
|
62
|
-
where: { name: 'system' },
|
|
63
|
-
}))) === null || _a === void 0 ? void 0 : _a.get({ plain: true });
|
|
64
|
-
if (!systemApp) {
|
|
65
|
-
systemApp = await open_2.AppModel.create({
|
|
66
|
-
name: 'system',
|
|
67
|
-
scopes: ['crons', 'system', 'dashboard'],
|
|
68
|
-
client_id: (0, util_1.createRandomString)(12, 12),
|
|
69
|
-
client_secret: (0, util_1.createRandomString)(24, 24),
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
else if (!systemApp.scopes.includes('dashboard')) {
|
|
73
|
-
await open_2.AppModel.update({ scopes: [...systemApp.scopes, 'dashboard'] }, { where: { name: 'system' } });
|
|
74
|
-
}
|
|
60
|
+
await openService.initializeSystemApp();
|
|
75
61
|
const [systemConfig] = await system_1.SystemModel.findOrCreate({
|
|
76
62
|
where: { type: system_1.AuthDataType.systemConfig },
|
|
77
63
|
});
|
|
@@ -119,22 +105,22 @@ exports.default = async () => {
|
|
|
119
105
|
}, 5000);
|
|
120
106
|
};
|
|
121
107
|
// 初始化更新 linux/python/nodejs 镜像源配置
|
|
122
|
-
if ((
|
|
108
|
+
if ((_a = systemConfig.info) === null || _a === void 0 ? void 0 : _a.pythonMirror) {
|
|
123
109
|
systemService.updatePythonMirror({
|
|
124
|
-
pythonMirror: (
|
|
110
|
+
pythonMirror: (_b = systemConfig.info) === null || _b === void 0 ? void 0 : _b.pythonMirror,
|
|
125
111
|
});
|
|
126
112
|
}
|
|
127
|
-
if ((
|
|
113
|
+
if ((_c = systemConfig.info) === null || _c === void 0 ? void 0 : _c.linuxMirror) {
|
|
128
114
|
systemService.updateLinuxMirror({
|
|
129
|
-
linuxMirror: (
|
|
115
|
+
linuxMirror: (_d = systemConfig.info) === null || _d === void 0 ? void 0 : _d.linuxMirror,
|
|
130
116
|
}, undefined, () => installDependencies());
|
|
131
117
|
}
|
|
132
118
|
else {
|
|
133
119
|
installDependencies();
|
|
134
120
|
}
|
|
135
|
-
if ((
|
|
121
|
+
if ((_e = systemConfig.info) === null || _e === void 0 ? void 0 : _e.nodeMirror) {
|
|
136
122
|
systemService.updateNodeMirror({
|
|
137
|
-
nodeMirror: (
|
|
123
|
+
nodeMirror: (_f = systemConfig.info) === null || _f === void 0 ? void 0 : _f.nodeMirror,
|
|
138
124
|
});
|
|
139
125
|
}
|
|
140
126
|
// 初始化新增默认全部任务视图
|
|
@@ -153,7 +139,11 @@ exports.default = async () => {
|
|
|
153
139
|
// 初始化更新所有任务状态为空闲
|
|
154
140
|
await cron_1.CrontabModel.update({ status: cron_1.CrontabStatus.idle }, { where: {} });
|
|
155
141
|
// 清空所有运行中的实例记录(服务重启后进程已不存在)
|
|
156
|
-
await runningInstance_1.RunningInstanceModel.update({
|
|
142
|
+
await runningInstance_1.RunningInstanceModel.update({
|
|
143
|
+
status: runningInstance_1.InstanceStatus.stopped,
|
|
144
|
+
finished_at: Math.floor(Date.now() / 1000),
|
|
145
|
+
// The previous process's exit code cannot be recovered after a restart.
|
|
146
|
+
}, { where: { status: runningInstance_1.InstanceStatus.running } });
|
|
157
147
|
// 初始化时执行一次所有的 ql repo 任务
|
|
158
148
|
cron_1.CrontabModel.findAll({
|
|
159
149
|
where: {
|
|
@@ -208,7 +198,7 @@ exports.default = async () => {
|
|
|
208
198
|
}
|
|
209
199
|
});
|
|
210
200
|
// 初始化语言(必须在 autosave_crontab 之前)
|
|
211
|
-
const lang = ((
|
|
201
|
+
const lang = ((_g = systemConfig.info) === null || _g === void 0 ? void 0 : _g.lang) || (0, i18n_1.systemLang)();
|
|
212
202
|
(0, i18n_1.setLang)(lang);
|
|
213
203
|
// 确保 lang_env.sh 存在
|
|
214
204
|
try {
|
|
@@ -217,16 +207,16 @@ exports.default = async () => {
|
|
|
217
207
|
await (0, promises_1.writeFile)(config_1.default.langEnvFile, `export QL_LANG='${lang}'\n`);
|
|
218
208
|
}
|
|
219
209
|
}
|
|
220
|
-
catch (
|
|
210
|
+
catch (_h) { }
|
|
221
211
|
// 初始化保存一次ck和定时任务数据
|
|
222
|
-
client_1.default.readiness.configure(() =>
|
|
212
|
+
client_1.default.readiness.configure(async () => {
|
|
213
|
+
await cronService.autosave_crontab(true);
|
|
214
|
+
await systemService.restoreCronConcurrency();
|
|
215
|
+
});
|
|
223
216
|
await client_1.default.readiness.recover();
|
|
224
217
|
await envService.set_envs();
|
|
225
218
|
const authInfo = await userService.getAuthInfo();
|
|
226
|
-
const apps = await openService.findApps();
|
|
227
219
|
await store_1.shareStore.updateAuthInfo(authInfo);
|
|
228
|
-
|
|
229
|
-
await store_1.shareStore.updateApps(apps);
|
|
230
|
-
}
|
|
220
|
+
await openService.refreshApps();
|
|
231
221
|
};
|
|
232
222
|
//# sourceMappingURL=initData.js.map
|
|
@@ -12,6 +12,8 @@ const config_1 = __importDefault(require("../config"));
|
|
|
12
12
|
const util_1 = require("../config/util");
|
|
13
13
|
const path_1 = require("path");
|
|
14
14
|
const i18n_1 = require("../shared/i18n");
|
|
15
|
+
const logger_1 = __importDefault(require("./logger"));
|
|
16
|
+
const subscriptionPath_1 = require("../shared/subscriptionPath");
|
|
15
17
|
exports.default = async () => {
|
|
16
18
|
const systemService = typedi_1.Container.get(system_1.default);
|
|
17
19
|
const scheduleService = typedi_1.Container.get(schedule_1.default);
|
|
@@ -23,6 +25,7 @@ exports.default = async () => {
|
|
|
23
25
|
if (await (0, util_1.fileExist)(tokenFile)) {
|
|
24
26
|
tokenCommand = `node ${tokenFile}`;
|
|
25
27
|
}
|
|
28
|
+
tokenCommand += ' --renew';
|
|
26
29
|
const cron = {
|
|
27
30
|
id: NaN,
|
|
28
31
|
name: (0, i18n_1.t)('生成token'),
|
|
@@ -57,7 +60,14 @@ exports.default = async () => {
|
|
|
57
60
|
await subscriptionService.setSshConfig();
|
|
58
61
|
const subs = await subscriptionService.list();
|
|
59
62
|
for (const sub of subs) {
|
|
60
|
-
|
|
63
|
+
try {
|
|
64
|
+
const doc = sub.get({ plain: true });
|
|
65
|
+
(0, subscriptionPath_1.assertSubscriptionAlias)(doc.alias);
|
|
66
|
+
await subscriptionService.handleTask(doc, !sub.is_disabled);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
logger_1.default.warn('跳过订阅 %s 的无效定时配置: %s', sub.id, error);
|
|
70
|
+
}
|
|
61
71
|
}
|
|
62
72
|
};
|
|
63
73
|
//# sourceMappingURL=initTask.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const sequelize_1 = require("sequelize");
|
|
4
|
+
const i18n_1 = require("../shared/i18n");
|
|
5
|
+
// Handle the database constraint itself so concurrent writes are covered too.
|
|
6
|
+
const uniqueConstraintError = (err, req, res, next) => {
|
|
7
|
+
if (!(err instanceof sequelize_1.UniqueConstraintError))
|
|
8
|
+
return next(err);
|
|
9
|
+
// Constraint details can contain environment values or application credentials.
|
|
10
|
+
res
|
|
11
|
+
.status(409)
|
|
12
|
+
.json({ code: 409, message: (0, i18n_1.t)('资源已存在,请检查重复的名称或值') });
|
|
13
|
+
};
|
|
14
|
+
exports.default = uniqueConstraintError;
|
|
15
|
+
//# sourceMappingURL=uniqueConstraintError.js.map
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
3
3
|
// versions:
|
|
4
4
|
// protoc-gen-ts_proto v2.6.1
|
|
5
|
-
// protoc
|
|
5
|
+
// protoc v5.28.3
|
|
6
6
|
// source: back/protos/cron.proto
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.CronClient = exports.CronService = exports.DeleteCronResponse = exports.DeleteCronRequest = exports.AddCronResponse = exports.AddCronRequest = exports.ICron = exports.ISchedule = exports.protobufPackage = void 0;
|
|
8
|
+
exports.CronClient = exports.CronService = exports.SetConcurrencyRequest = exports.DeleteCronResponse = exports.DeleteCronRequest = exports.AddCronResponse = exports.AddCronRequest = exports.ICron = exports.ISchedule = exports.protobufPackage = void 0;
|
|
9
9
|
/* eslint-disable */
|
|
10
10
|
const wire_1 = require("@bufbuild/protobuf/wire");
|
|
11
11
|
const grpc_js_1 = require("@grpc/grpc-js");
|
|
@@ -376,6 +376,58 @@ exports.DeleteCronResponse = {
|
|
|
376
376
|
return message;
|
|
377
377
|
},
|
|
378
378
|
};
|
|
379
|
+
function createBaseSetConcurrencyRequest() {
|
|
380
|
+
return { concurrency: 0 };
|
|
381
|
+
}
|
|
382
|
+
exports.SetConcurrencyRequest = {
|
|
383
|
+
encode(message, writer = new wire_1.BinaryWriter()) {
|
|
384
|
+
if (message.concurrency !== 0) {
|
|
385
|
+
writer.uint32(8).int32(message.concurrency);
|
|
386
|
+
}
|
|
387
|
+
return writer;
|
|
388
|
+
},
|
|
389
|
+
decode(input, length) {
|
|
390
|
+
const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
|
|
391
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
392
|
+
const message = createBaseSetConcurrencyRequest();
|
|
393
|
+
while (reader.pos < end) {
|
|
394
|
+
const tag = reader.uint32();
|
|
395
|
+
switch (tag >>> 3) {
|
|
396
|
+
case 1: {
|
|
397
|
+
if (tag !== 8) {
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
message.concurrency = reader.int32();
|
|
401
|
+
continue;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
405
|
+
break;
|
|
406
|
+
}
|
|
407
|
+
reader.skip(tag & 7);
|
|
408
|
+
}
|
|
409
|
+
return message;
|
|
410
|
+
},
|
|
411
|
+
fromJSON(object) {
|
|
412
|
+
return { concurrency: isSet(object.concurrency) ? globalThis.Number(object.concurrency) : 0 };
|
|
413
|
+
},
|
|
414
|
+
toJSON(message) {
|
|
415
|
+
const obj = {};
|
|
416
|
+
if (message.concurrency !== 0) {
|
|
417
|
+
obj.concurrency = Math.round(message.concurrency);
|
|
418
|
+
}
|
|
419
|
+
return obj;
|
|
420
|
+
},
|
|
421
|
+
create(base) {
|
|
422
|
+
return exports.SetConcurrencyRequest.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
423
|
+
},
|
|
424
|
+
fromPartial(object) {
|
|
425
|
+
var _a;
|
|
426
|
+
const message = createBaseSetConcurrencyRequest();
|
|
427
|
+
message.concurrency = (_a = object.concurrency) !== null && _a !== void 0 ? _a : 0;
|
|
428
|
+
return message;
|
|
429
|
+
},
|
|
430
|
+
};
|
|
379
431
|
exports.CronService = {
|
|
380
432
|
addCron: {
|
|
381
433
|
path: "/com.ql.cron.Cron/addCron",
|
|
@@ -395,6 +447,15 @@ exports.CronService = {
|
|
|
395
447
|
responseSerialize: (value) => Buffer.from(exports.DeleteCronResponse.encode(value).finish()),
|
|
396
448
|
responseDeserialize: (value) => exports.DeleteCronResponse.decode(value),
|
|
397
449
|
},
|
|
450
|
+
setConcurrency: {
|
|
451
|
+
path: "/com.ql.cron.Cron/setConcurrency",
|
|
452
|
+
requestStream: false,
|
|
453
|
+
responseStream: false,
|
|
454
|
+
requestSerialize: (value) => Buffer.from(exports.SetConcurrencyRequest.encode(value).finish()),
|
|
455
|
+
requestDeserialize: (value) => exports.SetConcurrencyRequest.decode(value),
|
|
456
|
+
responseSerialize: (value) => Buffer.from(exports.AddCronResponse.encode(value).finish()),
|
|
457
|
+
responseDeserialize: (value) => exports.AddCronResponse.decode(value),
|
|
458
|
+
},
|
|
398
459
|
};
|
|
399
460
|
exports.CronClient = (0, grpc_js_1.makeGenericClientConstructor)(exports.CronService, "com.ql.cron.Cron");
|
|
400
461
|
function isSet(value) {
|
|
@@ -5,42 +5,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.addCron = void 0;
|
|
7
7
|
const grpc_js_1 = require("@grpc/grpc-js");
|
|
8
|
-
const
|
|
8
|
+
const cronScheduler_1 = require("../shared/cronScheduler");
|
|
9
|
+
const cronSchedule_1 = require("../shared/cronSchedule");
|
|
9
10
|
const data_1 = require("./data");
|
|
10
11
|
const runCron_1 = require("../shared/runCron");
|
|
11
12
|
const logger_1 = __importDefault(require("../loaders/logger"));
|
|
12
13
|
const i18n_1 = require("../shared/i18n");
|
|
13
|
-
|
|
14
|
-
* 预校验 cron 表达式,检测 node-schedule 会拒绝但 cron-parser 会接受的 pattern。
|
|
15
|
-
* node-schedule 对 bare /N(字段以 / 开头,如前无星号/数字前缀的 /6)返回 null,
|
|
16
|
-
* 提前拦截避免走 scheduleJob 后才发现无效。
|
|
17
|
-
*/
|
|
14
|
+
// Validate the entire batch before replacing any existing jobs.
|
|
18
15
|
const isValidCronField = (cron) => {
|
|
19
|
-
|
|
20
|
-
// node-schedule 会对这种字段返回 null
|
|
21
|
-
if (/\s\/\d/.test(cron) || /^\/\d/.test(cron)) {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
// 检测 ? 字符:Quartz cron 语法,node-schedule 在大多数位置返回 null
|
|
25
|
-
// cron-parser 接受但 node-schedule 拒绝,提前拦截
|
|
26
|
-
if (/\?/.test(cron)) {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
return true;
|
|
16
|
+
return (0, cronSchedule_1.isValidCronSchedule)(cron);
|
|
30
17
|
};
|
|
31
18
|
const addCron = (call, callback) => {
|
|
32
|
-
var _a;
|
|
19
|
+
var _a, _b;
|
|
33
20
|
// ===== 第一遍:预校验所有 cron 表达式 =====
|
|
34
21
|
const validationErrors = [];
|
|
35
22
|
for (const item of call.request.crons) {
|
|
36
23
|
const { id, schedule, extra_schedules } = item;
|
|
37
24
|
if (!isValidCronField(schedule)) {
|
|
38
|
-
validationErrors.push((0, i18n_1.tf)('任务ID %s: 无效的 cron 表达式 "%s"
|
|
25
|
+
validationErrors.push((0, i18n_1.tf)('任务ID %s: 无效的 cron 表达式 "%s"', String(id), schedule));
|
|
39
26
|
}
|
|
40
27
|
if (extra_schedules === null || extra_schedules === void 0 ? void 0 : extra_schedules.length) {
|
|
41
28
|
extra_schedules.forEach((x) => {
|
|
42
29
|
if (!isValidCronField(x.schedule)) {
|
|
43
|
-
validationErrors.push((0, i18n_1.tf)('任务ID %s (extra_schedule): 无效的 cron 表达式 "%s"
|
|
30
|
+
validationErrors.push((0, i18n_1.tf)('任务ID %s (extra_schedule): 无效的 cron 表达式 "%s"', String(id), x.schedule));
|
|
44
31
|
}
|
|
45
32
|
});
|
|
46
33
|
}
|
|
@@ -53,52 +40,47 @@ const addCron = (call, callback) => {
|
|
|
53
40
|
callback(err, null);
|
|
54
41
|
return;
|
|
55
42
|
}
|
|
56
|
-
//
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
for (const
|
|
60
|
-
|
|
61
|
-
|
|
43
|
+
// Prepare stopped jobs first: construction errors must preserve the old snapshot.
|
|
44
|
+
const prepared = new Map();
|
|
45
|
+
try {
|
|
46
|
+
for (const item of call.request.crons) {
|
|
47
|
+
const jobs = [];
|
|
48
|
+
(_a = prepared.get(item.id)) === null || _a === void 0 ? void 0 : _a.forEach((job) => job.cancel());
|
|
49
|
+
prepared.set(item.id, jobs);
|
|
50
|
+
for (const schedule of [
|
|
51
|
+
item.schedule,
|
|
52
|
+
...(item.extra_schedules || []).map((x) => x.schedule),
|
|
53
|
+
]) {
|
|
54
|
+
jobs.push((0, cronScheduler_1.createCronJob)(schedule, async () => {
|
|
55
|
+
logger_1.default.info('[schedule][准备运行任务] 命令: %s', item.command);
|
|
56
|
+
await (0, runCron_1.runCron)(item.command, item, () => data_1.scheduleStacks.get(item.id) === jobs);
|
|
57
|
+
}, {
|
|
58
|
+
name: `${item.id}: ${item.name || ''}`,
|
|
59
|
+
logger: logger_1.default,
|
|
60
|
+
start: false,
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
62
63
|
}
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
for (const jobs of prepared.values())
|
|
67
|
+
jobs.forEach((job) => job.cancel());
|
|
68
|
+
const err = new Error(error instanceof Error ? error.message : String(error));
|
|
69
|
+
err.code = grpc_js_1.status.INVALID_ARGUMENT;
|
|
70
|
+
err.details = err.message;
|
|
71
|
+
callback(err, null);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (call.request.replace) {
|
|
75
|
+
for (const jobs of data_1.scheduleStacks.values())
|
|
76
|
+
jobs.forEach((job) => job === null || job === void 0 ? void 0 : job.cancel());
|
|
63
77
|
data_1.scheduleStacks.clear();
|
|
64
78
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
(_a = data_1.scheduleStacks.get(id)) === null || _a === void 0 ? void 0 : _a.forEach((x) => x.cancel());
|
|
71
|
-
}
|
|
72
|
-
logger_1.default.info('[schedule][创建定时任务] 任务ID: %s, 名称: %s, cron: %s, 执行命令: %s', id, name, schedule, command);
|
|
73
|
-
if (extra_schedules === null || extra_schedules === void 0 ? void 0 : extra_schedules.length) {
|
|
74
|
-
extra_schedules.forEach((x) => {
|
|
75
|
-
logger_1.default.info('[schedule][创建定时任务] 任务ID: %s, 名称: %s, cron: %s, 执行命令: %s', id, name, x.schedule, command);
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
const mainJob = node_schedule_1.default.scheduleJob(id, schedule, async () => {
|
|
79
|
-
logger_1.default.info(`[schedule][准备运行任务] 命令: ${command}`);
|
|
80
|
-
(0, runCron_1.runCron)(command, item);
|
|
81
|
-
});
|
|
82
|
-
if (!mainJob) {
|
|
83
|
-
logger_1.default.warn('[schedule][创建定时任务] scheduleJob 返回 null(不符合预期,已通过预校验): 任务ID: %s, cron: %s', id, schedule);
|
|
84
|
-
}
|
|
85
|
-
const extraJobs = (extra_schedules === null || extra_schedules === void 0 ? void 0 : extra_schedules.length)
|
|
86
|
-
? extra_schedules.map((x) => {
|
|
87
|
-
const job = node_schedule_1.default.scheduleJob(id, x.schedule, async () => {
|
|
88
|
-
logger_1.default.info(`[schedule][准备运行任务] 命令: ${command}`);
|
|
89
|
-
(0, runCron_1.runCron)(command, item);
|
|
90
|
-
});
|
|
91
|
-
if (!job) {
|
|
92
|
-
logger_1.default.warn('[schedule][创建定时任务] scheduleJob 返回 null(不符合预期,已通过预校验): 任务ID: %s, cron: %s', id, x.schedule);
|
|
93
|
-
}
|
|
94
|
-
return job;
|
|
95
|
-
})
|
|
96
|
-
: [];
|
|
97
|
-
// 过滤 null(兜底保护,正常情况下预校验已拦截)
|
|
98
|
-
const jobs = [mainJob, ...extraJobs].filter((x) => x != null);
|
|
99
|
-
if (jobs.length > 0) {
|
|
100
|
-
data_1.scheduleStacks.set(id, jobs);
|
|
101
|
-
}
|
|
79
|
+
for (const [id, jobs] of prepared) {
|
|
80
|
+
(_b = data_1.scheduleStacks.get(id)) === null || _b === void 0 ? void 0 : _b.forEach((job) => job.cancel());
|
|
81
|
+
data_1.scheduleStacks.set(id, jobs);
|
|
82
|
+
jobs.forEach((job) => job.start());
|
|
83
|
+
logger_1.default.info('[schedule][创建定时任务] 任务ID: %s, 规则数: %s', id, jobs.length);
|
|
102
84
|
}
|
|
103
85
|
callback(null, null);
|
|
104
86
|
};
|
|
@@ -38,10 +38,28 @@ class Client {
|
|
|
38
38
|
}
|
|
39
39
|
return this._client;
|
|
40
40
|
}
|
|
41
|
+
async setConcurrency(concurrency) {
|
|
42
|
+
await this.waitForReady(2000);
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
this.client.setConcurrency({ concurrency }, new grpc_js_1.Metadata(), { deadline: Date.now() + 5000 }, (err) => {
|
|
45
|
+
if (err) {
|
|
46
|
+
if (err.code === grpc_js_1.status.UNAVAILABLE || err.code === grpc_js_1.status.DEADLINE_EXCEEDED) {
|
|
47
|
+
this.readiness.invalidate();
|
|
48
|
+
Object.assign(err, { status: 503 });
|
|
49
|
+
}
|
|
50
|
+
return reject(err);
|
|
51
|
+
}
|
|
52
|
+
resolve();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
41
56
|
async addCron(request, replace = false) {
|
|
42
57
|
await this.waitForReady(2000);
|
|
58
|
+
// Include every rule in a recovery snapshot, but bound a stuck worker.
|
|
59
|
+
const ruleCount = request.reduce((count, item) => { var _a; return count + 1 + (((_a = item.extra_schedules) === null || _a === void 0 ? void 0 : _a.length) || 0); }, 0);
|
|
60
|
+
const registrationTimeoutMs = Math.min(120000, 5000 + ruleCount * 5);
|
|
43
61
|
return new Promise((resolve, reject) => {
|
|
44
|
-
this.client.addCron({ crons: request, replace }, new grpc_js_1.Metadata(), { deadline: Date.now() +
|
|
62
|
+
this.client.addCron({ crons: request, replace }, new grpc_js_1.Metadata(), { deadline: Date.now() + registrationTimeoutMs }, (err, res) => {
|
|
45
63
|
if (err) {
|
|
46
64
|
if (err.code === grpc_js_1.status.UNAVAILABLE || err.code === grpc_js_1.status.DEADLINE_EXCEEDED) {
|
|
47
65
|
// A timed-out write may already have reached the scheduler.
|
|
@@ -11,7 +11,7 @@ const delCron = (call, callback) => {
|
|
|
11
11
|
for (const id of call.request.ids) {
|
|
12
12
|
if (data_1.scheduleStacks.has(id)) {
|
|
13
13
|
logger_1.default.info('[schedule][取消定时任务] 任务ID: %s', id);
|
|
14
|
-
//
|
|
14
|
+
// 防御性过滤历史调度栈中的空任务,
|
|
15
15
|
// 否则对 null 调 cancel() 会让整个取消流程抛出 UNKNOWN 错误,
|
|
16
16
|
// 进而导致 HTTP 端的 remove() 跳过 setCrontab(),造成 crontab.list 残留。
|
|
17
17
|
(_a = data_1.scheduleStacks.get(id)) === null || _a === void 0 ? void 0 : _a.filter((x) => x != null).forEach((x) => {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.setConcurrency = void 0;
|
|
7
|
+
const grpc_js_1 = require("@grpc/grpc-js");
|
|
8
|
+
const os_1 = __importDefault(require("os"));
|
|
9
|
+
const pLimit_1 = __importDefault(require("../shared/pLimit"));
|
|
10
|
+
async function setConcurrency(call, callback) {
|
|
11
|
+
const limit = call.request.concurrency;
|
|
12
|
+
if (!Number.isInteger(limit) || limit < 0 || limit > 2147483647) {
|
|
13
|
+
callback(Object.assign(new Error('Invalid concurrency'), {
|
|
14
|
+
code: grpc_js_1.status.INVALID_ARGUMENT,
|
|
15
|
+
}), null);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
await pLimit_1.default.setCustomLimit(limit || Math.max(os_1.default.cpus().length, 4));
|
|
20
|
+
callback(null, {});
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
callback(error, null);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.setConcurrency = setConcurrency;
|
|
27
|
+
//# sourceMappingURL=setConcurrency.js.map
|
|
@@ -22,11 +22,10 @@ let ConfigService = class ConfigService {
|
|
|
22
22
|
constructor() { }
|
|
23
23
|
async getFile(filePath, res) {
|
|
24
24
|
let content = '';
|
|
25
|
-
if (!filePath) {
|
|
25
|
+
if (!filePath || filePath.startsWith('data/scripts/')) {
|
|
26
26
|
return res.send({ code: 403, message: (0, i18n_1.t)('文件无法访问') });
|
|
27
27
|
}
|
|
28
|
-
const
|
|
29
|
-
const resolved = (0, fileAccess_1.resolveFileAccess)(scriptFile ? config_1.default.scriptPath : config_1.default.configPath, [scriptFile ? filePath.slice('data/scripts/'.length) : filePath], config_1.default.blackFileList);
|
|
28
|
+
const resolved = (0, fileAccess_1.resolveFileAccess)(config_1.default.configPath, [filePath], config_1.default.blackFileList);
|
|
30
29
|
if (!resolved) {
|
|
31
30
|
return res.send({ code: 403, message: (0, i18n_1.t)('文件无法访问') });
|
|
32
31
|
}
|
|
@@ -16,15 +16,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
16
16
|
};
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
const crypto_1 = require("crypto");
|
|
19
|
+
const cronSchedule_1 = require("../shared/cronSchedule");
|
|
19
20
|
const schedulerMutationLock_1 = require("../shared/schedulerMutationLock");
|
|
20
21
|
const typedi_1 = require("typedi");
|
|
21
22
|
const winston_1 = __importDefault(require("winston"));
|
|
22
23
|
const config_1 = __importDefault(require("../config"));
|
|
24
|
+
const logPath_1 = require("../shared/logPath");
|
|
23
25
|
const cron_1 = require("../data/cron");
|
|
24
26
|
const runningInstance_1 = require("../data/runningInstance");
|
|
25
27
|
const child_process_1 = require("child_process");
|
|
26
28
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
27
|
-
const cron_parser_1 = __importDefault(require("cron-parser"));
|
|
28
29
|
const util_1 = require("../config/util");
|
|
29
30
|
const sequelize_1 = require("sequelize");
|
|
30
31
|
const path_1 = __importDefault(require("path"));
|
|
@@ -49,10 +50,19 @@ let CronService = class CronService {
|
|
|
49
50
|
}
|
|
50
51
|
isNodeCron(cron) {
|
|
51
52
|
const { schedule, extra_schedules } = cron;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return
|
|
53
|
+
const fields = (schedule === null || schedule === void 0 ? void 0 : schedule.trim().split(/\s+/)) || [];
|
|
54
|
+
// System crontab only receives portable numeric five-field expressions.
|
|
55
|
+
// Extended syntax, macros and legacy shorthand use the Node scheduler.
|
|
56
|
+
return (fields.length !== 5 ||
|
|
57
|
+
/[^\d\s*,/\-]/.test(schedule || '') ||
|
|
58
|
+
Boolean(extra_schedules === null || extra_schedules === void 0 ? void 0 : extra_schedules.length) ||
|
|
59
|
+
// BusyBox treats N/step as a single value and doesn't support Sunday=7.
|
|
60
|
+
fields.some((field) => field.split(',').some((part) => /^\d+\//.test(part))) ||
|
|
61
|
+
fields[4].includes('7') ||
|
|
62
|
+
// BusyBox steps DOM from zero; its full-range day/week wildcard
|
|
63
|
+
// handling also differs from the legacy Node parser's OR semantics.
|
|
64
|
+
fields[2].includes('/') ||
|
|
65
|
+
(fields[2] !== '*' && fields[4] !== '*'));
|
|
56
66
|
}
|
|
57
67
|
get schedulerMode() {
|
|
58
68
|
const env = process.env.QL_SCHEDULER;
|
|
@@ -196,6 +206,9 @@ let CronService = class CronService {
|
|
|
196
206
|
return await this.getDb({ id: payload.id });
|
|
197
207
|
}
|
|
198
208
|
async status({ ids, status, pid, log_path, last_running_time = 0, last_execution_time = 0, exit_code, }) {
|
|
209
|
+
if (log_path && log_path !== '/dev/null') {
|
|
210
|
+
(0, logPath_1.resolveLogPath)(config_1.default.logPath, log_path);
|
|
211
|
+
}
|
|
199
212
|
let options = {
|
|
200
213
|
status,
|
|
201
214
|
pid,
|
|
@@ -762,7 +775,9 @@ let CronService = class CronService {
|
|
|
762
775
|
truncated: false,
|
|
763
776
|
};
|
|
764
777
|
}
|
|
765
|
-
const absolutePath =
|
|
778
|
+
const absolutePath = doc.log_path
|
|
779
|
+
? (0, logPath_1.resolveLogPath)(config_1.default.logPath, doc.log_path)
|
|
780
|
+
: '';
|
|
766
781
|
const logFileExist = doc.log_path && (await (0, util_1.fileExist)(absolutePath));
|
|
767
782
|
if (logFileExist) {
|
|
768
783
|
const chunk = await (0, logReader_1.readLogChunk)(`${absolutePath}`, options);
|
|
@@ -787,11 +802,11 @@ let CronService = class CronService {
|
|
|
787
802
|
}
|
|
788
803
|
async logs(id) {
|
|
789
804
|
const doc = await this.getDb({ id });
|
|
790
|
-
if (!doc || !doc.log_path) {
|
|
805
|
+
if (!doc || !doc.log_path || doc.log_path === '/dev/null') {
|
|
791
806
|
return [];
|
|
792
807
|
}
|
|
793
808
|
const relativeDir = path_1.default.dirname(`${doc.log_path}`);
|
|
794
|
-
const dir = path_1.default.
|
|
809
|
+
const dir = path_1.default.dirname((0, logPath_1.resolveLogPath)(config_1.default.logPath, doc.log_path));
|
|
795
810
|
const dirExist = await (0, util_1.fileExist)(dir);
|
|
796
811
|
if (dirExist) {
|
|
797
812
|
let files = await promises_1.default.readdir(dir);
|
|
@@ -880,7 +895,7 @@ let CronService = class CronService {
|
|
|
880
895
|
const schedule = line.replace(command, '').trim();
|
|
881
896
|
if (command &&
|
|
882
897
|
schedule &&
|
|
883
|
-
|
|
898
|
+
(0, cronSchedule_1.isValidCronSchedule)(schedule)) {
|
|
884
899
|
const name = namePrefix + '_' + index;
|
|
885
900
|
const _crontab = await cron_1.CrontabModel.findOne({
|
|
886
901
|
where: { command, schedule },
|
|
@@ -900,6 +915,17 @@ let CronService = class CronService {
|
|
|
900
915
|
async autosave_crontab(requireScheduler = false) {
|
|
901
916
|
return (0, schedulerMutationLock_1.withSchedulerMutation)(async () => {
|
|
902
917
|
const tabs = await this.crontabs();
|
|
918
|
+
// A bad persisted rule must not block startup or all other schedules.
|
|
919
|
+
// Keep the DB row editable; omit it from both runtime scheduler snapshots.
|
|
920
|
+
tabs.data = tabs.data.filter((doc) => {
|
|
921
|
+
if (doc.isDisabled === 1)
|
|
922
|
+
return true;
|
|
923
|
+
const invalidSchedules = (0, cronSchedule_1.getInvalidCronSchedules)(doc);
|
|
924
|
+
if (invalidSchedules.length === 0)
|
|
925
|
+
return true;
|
|
926
|
+
this.logger.warn('[crontab] Skipping task with invalid schedule (id=%s, name=%s): %s', doc.id, doc.name || '', JSON.stringify(invalidSchedules));
|
|
927
|
+
return false;
|
|
928
|
+
});
|
|
903
929
|
const regularCrons = tabs.data
|
|
904
930
|
.filter((x) => x.isDisabled !== 1 &&
|
|
905
931
|
this.shouldUseCronClient(x))
|
|
@@ -922,7 +948,7 @@ let CronService = class CronService {
|
|
|
922
948
|
await client_1.default.addCron(regularCrons, requireScheduler);
|
|
923
949
|
}
|
|
924
950
|
catch (error) {
|
|
925
|
-
this.logger.warn('[crontab] Failed to register cron job in scheduler:', (error === null || error === void 0 ? void 0 : error.message) || error);
|
|
951
|
+
this.logger.warn('[crontab] Failed to register cron job in scheduler: %s', (error === null || error === void 0 ? void 0 : error.message) || error);
|
|
926
952
|
if (requireScheduler)
|
|
927
953
|
throw error;
|
|
928
954
|
}
|