demo 环境不自动运行任务

This commit is contained in:
whyour
2025-05-08 01:43:14 +08:00
parent 710a107e73
commit 8174762c18
3 changed files with 24 additions and 10 deletions
+18 -8
View File
@@ -11,6 +11,7 @@ import {
killTask,
getUniqPath,
safeJSONParse,
isDemoEnv,
} from '../config/util';
import { Op, where, col as colFn, FindOptions, fn, Order } from 'sequelize';
import path from 'path';
@@ -53,6 +54,10 @@ export default class CronService {
tab.saved = false;
const doc = await this.insert(tab);
if (isDemoEnv()) {
return doc;
}
if (this.isNodeCron(doc) && !this.isSpecialSchedule(doc.schedule)) {
await cronClient.addCron([
{
@@ -79,7 +84,7 @@ export default class CronService {
tab.saved = false;
const newDoc = await this.updateDb(tab);
if (doc.isDisabled === 1) {
if (doc.isDisabled === 1 || isDemoEnv()) {
return newDoc;
}
@@ -528,7 +533,7 @@ export default class CronService {
await CrontabModel.update({ isDisabled: 0 }, { where: { id: ids } });
const docs = await CrontabModel.findAll({ where: { id: ids } });
const sixCron = docs
.filter((x) => this.isNodeCron(x))
.filter((x) => this.isNodeCron(x) && !this.isSpecialSchedule(x.schedule))
.map((doc) => ({
name: doc.name || '',
id: String(doc.id),
@@ -536,6 +541,10 @@ export default class CronService {
command: this.makeCommand(doc),
extra_schedules: doc.extra_schedules || [],
}));
if (isDemoEnv()) {
return;
}
await cronClient.addCron(sixCron);
await this.setCrontab();
}
@@ -609,11 +618,9 @@ export default class CronService {
const tabs = data ?? (await this.crontabs());
var crontab_string = '';
tabs.data.forEach((tab) => {
const _schedule = tab.schedule && tab.schedule.split(/ +/);
if (
tab.isDisabled === 1 ||
_schedule!.length !== 5 ||
tab.extra_schedules?.length ||
this.isNodeCron(tab) ||
this.isSpecialSchedule(tab.schedule)
) {
crontab_string += '# ';
@@ -671,13 +678,11 @@ export default class CronService {
public async autosave_crontab() {
const tabs = await this.crontabs();
this.setCrontab(tabs);
const regularCrons = tabs.data
.filter(
(x) =>
this.isNodeCron(x) &&
x.isDisabled !== 1 &&
this.isNodeCron(x) &&
!this.isSpecialSchedule(x.schedule),
)
.map((doc) => ({
@@ -687,7 +692,12 @@ export default class CronService {
command: this.makeCommand(doc),
extra_schedules: doc.extra_schedules || [],
}));
if (isDemoEnv()) {
return;
}
await cronClient.addCron(regularCrons);
this.setCrontab(tabs);
}
public async bootTask() {