mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-22 22:36:06 +08:00
demo 环境不自动运行任务
This commit is contained in:
parent
710a107e73
commit
8174762c18
|
@ -8,6 +8,7 @@ import path from 'path';
|
||||||
import { v4 as uuidV4 } from 'uuid';
|
import { v4 as uuidV4 } from 'uuid';
|
||||||
import rateLimit from 'express-rate-limit';
|
import rateLimit from 'express-rate-limit';
|
||||||
import config from '../config';
|
import config from '../config';
|
||||||
|
import { isDemoEnv } from '../config/util';
|
||||||
const route = Router();
|
const route = Router();
|
||||||
|
|
||||||
const storage = multer.diskStorage({
|
const storage = multer.diskStorage({
|
||||||
|
@ -72,9 +73,8 @@ export default (app: Router) => {
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
async (req: Request, res: Response, next: NextFunction) => {
|
async (req: Request, res: Response, next: NextFunction) => {
|
||||||
const logger: Logger = Container.get('logger');
|
|
||||||
try {
|
try {
|
||||||
if (process.env.DeployEnv === 'demo') {
|
if (isDemoEnv()) {
|
||||||
return res.send({ code: 450, message: '未知错误' });
|
return res.send({ code: 450, message: '未知错误' });
|
||||||
}
|
}
|
||||||
const userService = Container.get(UserService);
|
const userService = Container.get(UserService);
|
||||||
|
|
|
@ -618,3 +618,7 @@ export function getUninstallCommand(
|
||||||
|
|
||||||
return `${baseCommands[type]} ${name.trim()}`;
|
return `${baseCommands[type]} ${name.trim()}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isDemoEnv() {
|
||||||
|
return process.env.DeployEnv === 'demo';
|
||||||
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import {
|
||||||
killTask,
|
killTask,
|
||||||
getUniqPath,
|
getUniqPath,
|
||||||
safeJSONParse,
|
safeJSONParse,
|
||||||
|
isDemoEnv,
|
||||||
} from '../config/util';
|
} from '../config/util';
|
||||||
import { Op, where, col as colFn, FindOptions, fn, Order } from 'sequelize';
|
import { Op, where, col as colFn, FindOptions, fn, Order } from 'sequelize';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
@ -53,6 +54,10 @@ export default class CronService {
|
||||||
tab.saved = false;
|
tab.saved = false;
|
||||||
const doc = await this.insert(tab);
|
const doc = await this.insert(tab);
|
||||||
|
|
||||||
|
if (isDemoEnv()) {
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.isNodeCron(doc) && !this.isSpecialSchedule(doc.schedule)) {
|
if (this.isNodeCron(doc) && !this.isSpecialSchedule(doc.schedule)) {
|
||||||
await cronClient.addCron([
|
await cronClient.addCron([
|
||||||
{
|
{
|
||||||
|
@ -79,7 +84,7 @@ export default class CronService {
|
||||||
tab.saved = false;
|
tab.saved = false;
|
||||||
const newDoc = await this.updateDb(tab);
|
const newDoc = await this.updateDb(tab);
|
||||||
|
|
||||||
if (doc.isDisabled === 1) {
|
if (doc.isDisabled === 1 || isDemoEnv()) {
|
||||||
return newDoc;
|
return newDoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -528,7 +533,7 @@ export default class CronService {
|
||||||
await CrontabModel.update({ isDisabled: 0 }, { where: { id: ids } });
|
await CrontabModel.update({ isDisabled: 0 }, { where: { id: ids } });
|
||||||
const docs = await CrontabModel.findAll({ where: { id: ids } });
|
const docs = await CrontabModel.findAll({ where: { id: ids } });
|
||||||
const sixCron = docs
|
const sixCron = docs
|
||||||
.filter((x) => this.isNodeCron(x))
|
.filter((x) => this.isNodeCron(x) && !this.isSpecialSchedule(x.schedule))
|
||||||
.map((doc) => ({
|
.map((doc) => ({
|
||||||
name: doc.name || '',
|
name: doc.name || '',
|
||||||
id: String(doc.id),
|
id: String(doc.id),
|
||||||
|
@ -536,6 +541,10 @@ export default class CronService {
|
||||||
command: this.makeCommand(doc),
|
command: this.makeCommand(doc),
|
||||||
extra_schedules: doc.extra_schedules || [],
|
extra_schedules: doc.extra_schedules || [],
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
if (isDemoEnv()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
await cronClient.addCron(sixCron);
|
await cronClient.addCron(sixCron);
|
||||||
await this.setCrontab();
|
await this.setCrontab();
|
||||||
}
|
}
|
||||||
|
@ -609,11 +618,9 @@ export default class CronService {
|
||||||
const tabs = data ?? (await this.crontabs());
|
const tabs = data ?? (await this.crontabs());
|
||||||
var crontab_string = '';
|
var crontab_string = '';
|
||||||
tabs.data.forEach((tab) => {
|
tabs.data.forEach((tab) => {
|
||||||
const _schedule = tab.schedule && tab.schedule.split(/ +/);
|
|
||||||
if (
|
if (
|
||||||
tab.isDisabled === 1 ||
|
tab.isDisabled === 1 ||
|
||||||
_schedule!.length !== 5 ||
|
this.isNodeCron(tab) ||
|
||||||
tab.extra_schedules?.length ||
|
|
||||||
this.isSpecialSchedule(tab.schedule)
|
this.isSpecialSchedule(tab.schedule)
|
||||||
) {
|
) {
|
||||||
crontab_string += '# ';
|
crontab_string += '# ';
|
||||||
|
@ -671,13 +678,11 @@ export default class CronService {
|
||||||
|
|
||||||
public async autosave_crontab() {
|
public async autosave_crontab() {
|
||||||
const tabs = await this.crontabs();
|
const tabs = await this.crontabs();
|
||||||
this.setCrontab(tabs);
|
|
||||||
|
|
||||||
const regularCrons = tabs.data
|
const regularCrons = tabs.data
|
||||||
.filter(
|
.filter(
|
||||||
(x) =>
|
(x) =>
|
||||||
this.isNodeCron(x) &&
|
|
||||||
x.isDisabled !== 1 &&
|
x.isDisabled !== 1 &&
|
||||||
|
this.isNodeCron(x) &&
|
||||||
!this.isSpecialSchedule(x.schedule),
|
!this.isSpecialSchedule(x.schedule),
|
||||||
)
|
)
|
||||||
.map((doc) => ({
|
.map((doc) => ({
|
||||||
|
@ -687,7 +692,12 @@ export default class CronService {
|
||||||
command: this.makeCommand(doc),
|
command: this.makeCommand(doc),
|
||||||
extra_schedules: doc.extra_schedules || [],
|
extra_schedules: doc.extra_schedules || [],
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
if (isDemoEnv()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
await cronClient.addCron(regularCrons);
|
await cronClient.addCron(regularCrons);
|
||||||
|
this.setCrontab(tabs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async bootTask() {
|
public async bootTask() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user