mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-23 14:56:07 +08:00
修改日志路径合并方式
This commit is contained in:
parent
85facc039a
commit
92673b4a17
|
@ -195,10 +195,7 @@ export default class CronService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const err = await this.killTask(doc.command);
|
const err = await this.killTask(doc.command);
|
||||||
const absolutePath = path.join(
|
const absolutePath = path.resolve(config.logPath, `${doc.log_path}`);
|
||||||
config.logPath,
|
|
||||||
`${doc.log_path?.replace(config.logPath, '')}`,
|
|
||||||
);
|
|
||||||
const logFileExist = await fileExist(absolutePath);
|
const logFileExist = await fileExist(absolutePath);
|
||||||
if (doc.log_path && logFileExist) {
|
if (doc.log_path && logFileExist) {
|
||||||
const str = err ? `\n${err}` : '';
|
const str = err ? `\n${err}` : '';
|
||||||
|
@ -261,11 +258,8 @@ export default class CronService {
|
||||||
}
|
}
|
||||||
|
|
||||||
let { id, command, log_path } = cron;
|
let { id, command, log_path } = cron;
|
||||||
const absolutePath = path.join(
|
const absolutePath = path.resolve(config.logPath, `${log_path}`);
|
||||||
config.logPath,
|
const logFileExist = log_path && (await fileExist(absolutePath));
|
||||||
`${log_path?.replace(config.logPath, '')}`,
|
|
||||||
);
|
|
||||||
const logFileExist = await fileExist(absolutePath);
|
|
||||||
|
|
||||||
this.logger.silly('Running job');
|
this.logger.silly('Running job');
|
||||||
this.logger.silly('ID: ' + id);
|
this.logger.silly('ID: ' + id);
|
||||||
|
@ -333,10 +327,7 @@ export default class CronService {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
const absolutePath = path.join(
|
const absolutePath = path.resolve(config.logPath, `${doc.log_path}`);
|
||||||
config.logPath,
|
|
||||||
`${doc.log_path?.replace(config.logPath, '')}`,
|
|
||||||
);
|
|
||||||
const logFileExist = await fileExist(absolutePath);
|
const logFileExist = await fileExist(absolutePath);
|
||||||
if (logFileExist) {
|
if (logFileExist) {
|
||||||
return getFileContentByName(`${absolutePath}`);
|
return getFileContentByName(`${absolutePath}`);
|
||||||
|
@ -369,10 +360,8 @@ export default class CronService {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (doc.log_path) {
|
if (doc.log_path) {
|
||||||
const relativeDir = `${doc.log_path
|
const relativeDir = `${doc.log_path.replace(/\/[^\/]\..*/, '')}`;
|
||||||
.replace(/\/[^\/]\..*/, '')
|
const dir = path.resolve(config.logPath, relativeDir);
|
||||||
.replace(config.logPath, '')}`;
|
|
||||||
const dir = `${config.logPath}${relativeDir}`;
|
|
||||||
if (existsSync(dir)) {
|
if (existsSync(dir)) {
|
||||||
let files = await promises.readdir(dir);
|
let files = await promises.readdir(dir);
|
||||||
return files
|
return files
|
||||||
|
@ -432,7 +421,7 @@ export default class CronService {
|
||||||
var crontab_string = '';
|
var crontab_string = '';
|
||||||
tabs.forEach((tab) => {
|
tabs.forEach((tab) => {
|
||||||
const _schedule = tab.schedule && tab.schedule.split(/ +/);
|
const _schedule = tab.schedule && tab.schedule.split(/ +/);
|
||||||
if (tab.isDisabled === 1 || _schedule.length !== 5) {
|
if (tab.isDisabled === 1 || _schedule!.length !== 5) {
|
||||||
crontab_string += '# ';
|
crontab_string += '# ';
|
||||||
crontab_string += tab.schedule;
|
crontab_string += tab.schedule;
|
||||||
crontab_string += ' ';
|
crontab_string += ' ';
|
||||||
|
@ -458,22 +447,22 @@ export default class CronService {
|
||||||
|
|
||||||
public import_crontab() {
|
public import_crontab() {
|
||||||
exec('crontab -l', (error, stdout, stderr) => {
|
exec('crontab -l', (error, stdout, stderr) => {
|
||||||
var lines = stdout.split('\n');
|
const lines = stdout.split('\n');
|
||||||
var namePrefix = new Date().getTime();
|
const namePrefix = new Date().getTime();
|
||||||
|
|
||||||
lines.reverse().forEach(async (line, index) => {
|
lines.reverse().forEach(async (line, index) => {
|
||||||
line = line.replace(/\t+/g, ' ');
|
line = line.replace(/\t+/g, ' ');
|
||||||
var regex =
|
const regex =
|
||||||
/^((\@[a-zA-Z]+\s+)|(([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+))/;
|
/^((\@[a-zA-Z]+\s+)|(([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+))/;
|
||||||
var command = line.replace(regex, '').trim();
|
const command = line.replace(regex, '').trim();
|
||||||
var schedule = line.replace(command, '').trim();
|
const schedule = line.replace(command, '').trim();
|
||||||
|
|
||||||
if (
|
if (
|
||||||
command &&
|
command &&
|
||||||
schedule &&
|
schedule &&
|
||||||
cron_parser.parseExpression(schedule).hasNext()
|
cron_parser.parseExpression(schedule).hasNext()
|
||||||
) {
|
) {
|
||||||
var name = namePrefix + '_' + index;
|
const name = namePrefix + '_' + index;
|
||||||
|
|
||||||
const _crontab = await CrontabModel.findOne({
|
const _crontab = await CrontabModel.findOne({
|
||||||
where: { command, schedule },
|
where: { command, schedule },
|
||||||
|
|
Loading…
Reference in New Issue
Block a user