mirror of
https://github.com/whyour/qinglong.git
synced 2025-07-07 20:06:08 +08:00
任务面板支持查看最新日志
This commit is contained in:
parent
4d4d31431d
commit
e03c64dceb
|
@ -5,6 +5,7 @@ import * as fs from 'fs';
|
||||||
import config from '../config';
|
import config from '../config';
|
||||||
import jwt from 'jsonwebtoken';
|
import jwt from 'jsonwebtoken';
|
||||||
import { createPassword } from '../config/util';
|
import { createPassword } from '../config/util';
|
||||||
|
import crypto from 'crypto';
|
||||||
const route = Router();
|
const route = Router();
|
||||||
|
|
||||||
export default (app: Router) => {
|
export default (app: Router) => {
|
||||||
|
@ -41,11 +42,11 @@ export default (app: Router) => {
|
||||||
username == authInfo.username &&
|
username == authInfo.username &&
|
||||||
password == authInfo.password
|
password == authInfo.password
|
||||||
) {
|
) {
|
||||||
let token = jwt.sign(
|
const data = createPassword(50, 100);
|
||||||
{ username, password },
|
let token = jwt.sign({ data }, config.secret as any, {
|
||||||
config.secret as any,
|
expiresIn: 60 * 60 * 24 * 3,
|
||||||
{ expiresIn: 60 * 60 * 24 * 7, algorithm: 'HS384' },
|
algorithm: 'HS384',
|
||||||
);
|
});
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
config.authConfigFile,
|
config.authConfigFile,
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
|
|
|
@ -18,7 +18,9 @@ export class Crontab {
|
||||||
this.saved = options.saved;
|
this.saved = options.saved;
|
||||||
this._id = options._id;
|
this._id = options._id;
|
||||||
this.created = options.created;
|
this.created = options.created;
|
||||||
this.status = options.status || CrontabStatus.idle;
|
this.status = CrontabStatus[options.status]
|
||||||
|
? options.status
|
||||||
|
: CrontabStatus.idle;
|
||||||
this.timestamp = new Date().toString();
|
this.timestamp = new Date().toString();
|
||||||
this.isSystem = options.isSystem || 0;
|
this.isSystem = options.isSystem || 0;
|
||||||
this.pid = options.pid;
|
this.pid = options.pid;
|
||||||
|
|
|
@ -8,6 +8,7 @@ import fs from 'fs';
|
||||||
import cron_parser from 'cron-parser';
|
import cron_parser from 'cron-parser';
|
||||||
import { getFileContentByName } from '../config/util';
|
import { getFileContentByName } from '../config/util';
|
||||||
import PQueue from 'p-queue';
|
import PQueue from 'p-queue';
|
||||||
|
import { promises, existsSync } from 'fs';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class CronService {
|
export default class CronService {
|
||||||
|
@ -275,8 +276,22 @@ export default class CronService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async log(_id: string) {
|
public async log(_id: string) {
|
||||||
let logFile = `${config.manualLogPath}${_id}.log`;
|
const doc = await this.get(_id);
|
||||||
return getFileContentByName(logFile);
|
const commandStr = doc.command.split(' ')[1];
|
||||||
|
const start =
|
||||||
|
commandStr.lastIndexOf('/') !== -1 ? commandStr.lastIndexOf('/') + 1 : 0;
|
||||||
|
const end =
|
||||||
|
commandStr.lastIndexOf('.') !== -1
|
||||||
|
? commandStr.lastIndexOf('.')
|
||||||
|
: commandStr.length;
|
||||||
|
const logPath = commandStr.substring(start, end);
|
||||||
|
let logDir = `${config.logPath}${logPath}`;
|
||||||
|
if (existsSync(logDir)) {
|
||||||
|
const files = await promises.readdir(logDir);
|
||||||
|
return getFileContentByName(`${logDir}/${files[files.length - 1]}`);
|
||||||
|
} else {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private make_command(tab: Crontab) {
|
private make_command(tab: Crontab) {
|
||||||
|
|
|
@ -108,7 +108,8 @@ run_concurrent() {
|
||||||
local array=($(echo $envs | sed 's/&/ /g'))
|
local array=($(echo $envs | sed 's/&/ /g'))
|
||||||
cd $dir_scripts
|
cd $dir_scripts
|
||||||
define_program "$p1"
|
define_program "$p1"
|
||||||
log_dir="$dir_log/${p1%%.*}"
|
log_dir_tmp="${p1##*/}"
|
||||||
|
log_dir="$dir_log/${log_dir_tmp%%.*}"
|
||||||
make_dir $log_dir
|
make_dir $log_dir
|
||||||
log_time=$(date "+%Y-%m-%d-%H-%M-%S.%N")
|
log_time=$(date "+%Y-%m-%d-%H-%M-%S.%N")
|
||||||
echo -e "\n各账号间已经在后台开始并发执行,前台不输入日志,日志直接写入文件中。\n"
|
echo -e "\n各账号间已经在后台开始并发执行,前台不输入日志,日志直接写入文件中。\n"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user