mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-22 22:36:06 +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 jwt from 'jsonwebtoken';
|
||||
import { createPassword } from '../config/util';
|
||||
import crypto from 'crypto';
|
||||
const route = Router();
|
||||
|
||||
export default (app: Router) => {
|
||||
|
@ -41,11 +42,11 @@ export default (app: Router) => {
|
|||
username == authInfo.username &&
|
||||
password == authInfo.password
|
||||
) {
|
||||
let token = jwt.sign(
|
||||
{ username, password },
|
||||
config.secret as any,
|
||||
{ expiresIn: 60 * 60 * 24 * 7, algorithm: 'HS384' },
|
||||
);
|
||||
const data = createPassword(50, 100);
|
||||
let token = jwt.sign({ data }, config.secret as any, {
|
||||
expiresIn: 60 * 60 * 24 * 3,
|
||||
algorithm: 'HS384',
|
||||
});
|
||||
fs.writeFileSync(
|
||||
config.authConfigFile,
|
||||
JSON.stringify({
|
||||
|
|
|
@ -18,7 +18,9 @@ export class Crontab {
|
|||
this.saved = options.saved;
|
||||
this._id = options._id;
|
||||
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.isSystem = options.isSystem || 0;
|
||||
this.pid = options.pid;
|
||||
|
|
|
@ -8,6 +8,7 @@ import fs from 'fs';
|
|||
import cron_parser from 'cron-parser';
|
||||
import { getFileContentByName } from '../config/util';
|
||||
import PQueue from 'p-queue';
|
||||
import { promises, existsSync } from 'fs';
|
||||
|
||||
@Service()
|
||||
export default class CronService {
|
||||
|
@ -275,8 +276,22 @@ export default class CronService {
|
|||
}
|
||||
|
||||
public async log(_id: string) {
|
||||
let logFile = `${config.manualLogPath}${_id}.log`;
|
||||
return getFileContentByName(logFile);
|
||||
const doc = await this.get(_id);
|
||||
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) {
|
||||
|
|
|
@ -108,7 +108,8 @@ run_concurrent() {
|
|||
local array=($(echo $envs | sed 's/&/ /g'))
|
||||
cd $dir_scripts
|
||||
define_program "$p1"
|
||||
log_dir="$dir_log/${p1%%.*}"
|
||||
log_dir_tmp="${p1##*/}"
|
||||
log_dir="$dir_log/${log_dir_tmp%%.*}"
|
||||
make_dir $log_dir
|
||||
log_time=$(date "+%Y-%m-%d-%H-%M-%S.%N")
|
||||
echo -e "\n各账号间已经在后台开始并发执行,前台不输入日志,日志直接写入文件中。\n"
|
||||
|
|
Loading…
Reference in New Issue
Block a user