mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-22 22:36:06 +08:00
修复删除日志命令
This commit is contained in:
parent
4e5ad6d5f3
commit
8b042d90f3
|
@ -15,6 +15,7 @@ export default (app: Router) => {
|
||||||
const subscriptionService = Container.get(SubscriptionService);
|
const subscriptionService = Container.get(SubscriptionService);
|
||||||
const data = await subscriptionService.list(
|
const data = await subscriptionService.list(
|
||||||
req.query.searchValue as string,
|
req.query.searchValue as string,
|
||||||
|
req.query.ids as string,
|
||||||
);
|
);
|
||||||
return res.send({ code: 200, data });
|
return res.send({ code: 200, data });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -212,8 +213,8 @@ export default (app: Router) => {
|
||||||
body: Joi.array().items(Joi.number().required()),
|
body: Joi.array().items(Joi.number().required()),
|
||||||
query: Joi.object({
|
query: Joi.object({
|
||||||
force: Joi.boolean().optional(),
|
force: Joi.boolean().optional(),
|
||||||
t: Joi.number()
|
t: Joi.number(),
|
||||||
})
|
}),
|
||||||
}),
|
}),
|
||||||
async (req: Request, res: Response, next: NextFunction) => {
|
async (req: Request, res: Response, next: NextFunction) => {
|
||||||
const logger: Logger = Container.get('logger');
|
const logger: Logger = Container.get('logger');
|
||||||
|
|
|
@ -12,7 +12,7 @@ import {
|
||||||
getUniqPath,
|
getUniqPath,
|
||||||
safeJSONParse,
|
safeJSONParse,
|
||||||
} from '../config/util';
|
} from '../config/util';
|
||||||
import { Op, where, col as colFn, FindOptions, fn } from 'sequelize';
|
import { Op, where, col as colFn, FindOptions, fn, Order } from 'sequelize';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { TASK_PREFIX, QL_PREFIX } from '../config/const';
|
import { TASK_PREFIX, QL_PREFIX } from '../config/const';
|
||||||
import cronClient from '../schedule/client';
|
import cronClient from '../schedule/client';
|
||||||
|
@ -362,9 +362,9 @@ export default class CronService {
|
||||||
order.unshift([field, type]);
|
order.unshift([field, type]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let condition: any = {
|
let condition: FindOptions<Crontab> = {
|
||||||
where: query,
|
where: query,
|
||||||
order: order,
|
order: order as Order,
|
||||||
};
|
};
|
||||||
if (page && size) {
|
if (page && size) {
|
||||||
condition.offset = (page - 1) * size;
|
condition.offset = (page - 1) * size;
|
||||||
|
|
|
@ -41,8 +41,12 @@ export default class SubscriptionService {
|
||||||
private crontabService: CrontabService,
|
private crontabService: CrontabService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public async list(searchText?: string): Promise<Subscription[]> {
|
public async list(
|
||||||
|
searchText?: string,
|
||||||
|
ids?: string,
|
||||||
|
): Promise<Subscription[]> {
|
||||||
let query = {};
|
let query = {};
|
||||||
|
const subIds = JSON.parse(ids || '[]');
|
||||||
if (searchText) {
|
if (searchText) {
|
||||||
const reg = {
|
const reg = {
|
||||||
[Op.or]: [
|
[Op.or]: [
|
||||||
|
@ -63,7 +67,7 @@ export default class SubscriptionService {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const result = await SubscriptionModel.findAll({
|
const result = await SubscriptionModel.findAll({
|
||||||
where: query,
|
where: { ...query, ...(ids ? { id: subIds } : undefined) },
|
||||||
order: [
|
order: [
|
||||||
['is_disabled', 'ASC'],
|
['is_disabled', 'ASC'],
|
||||||
['createdAt', 'DESC'],
|
['createdAt', 'DESC'],
|
||||||
|
|
|
@ -2,13 +2,18 @@
|
||||||
|
|
||||||
days=$1
|
days=$1
|
||||||
|
|
||||||
## 删除运行脚本的旧日志
|
|
||||||
remove_js_log() {
|
remove_js_log() {
|
||||||
local log_full_path_list=$(find $dir_log/ -name "*.log")
|
local log_full_path_list=$(find $dir_log -name "*.log")
|
||||||
local diff_time
|
local diff_time
|
||||||
for log in $log_full_path_list; do
|
for log in $log_full_path_list; do
|
||||||
local log_date=$(echo $log | awk -F "/" '{print $NF}' | cut -c1-10) #文件名比文件属性获得的日期要可靠
|
local log_date=$(echo $log | awk -F "/" '{print $NF}' | cut -c1-10)
|
||||||
if [[ $(date +%s -d $log_date 2>/dev/null) ]]; then
|
if ! [[ $log_date =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
|
||||||
|
if [[ $is_macos -eq 1 ]]; then
|
||||||
|
log_date=$(stat -f %Sm -t "%Y-%m-%d" "$log")
|
||||||
|
else
|
||||||
|
log_date=$(stat -c %y "$log" | cut -d ' ' -f 1)
|
||||||
|
fi
|
||||||
|
fi
|
||||||
if [[ $is_macos -eq 1 ]]; then
|
if [[ $is_macos -eq 1 ]]; then
|
||||||
diff_time=$(($(date +%s) - $(date -j -f "%Y-%m-%d" "$log_date" +%s)))
|
diff_time=$(($(date +%s) - $(date -j -f "%Y-%m-%d" "$log_date" +%s)))
|
||||||
else
|
else
|
||||||
|
@ -25,11 +30,9 @@ remove_js_log() {
|
||||||
echo -e "正在被 $result 使用,跳过~"
|
echo -e "正在被 $result 使用,跳过~"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
## 删除空文件夹
|
|
||||||
remove_empty_dir() {
|
remove_empty_dir() {
|
||||||
cd $dir_log
|
cd $dir_log
|
||||||
for dir in $(ls); do
|
for dir in $(ls); do
|
||||||
|
@ -39,7 +42,6 @@ remove_empty_dir() {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
## 运行
|
|
||||||
if [[ ${days} ]]; then
|
if [[ ${days} ]]; then
|
||||||
echo -e "查找旧日志文件中...\n"
|
echo -e "查找旧日志文件中...\n"
|
||||||
remove_js_log
|
remove_js_log
|
||||||
|
|
|
@ -267,22 +267,7 @@ const Crontab = () => {
|
||||||
{
|
{
|
||||||
title: intl.get('关联订阅'),
|
title: intl.get('关联订阅'),
|
||||||
width: 185,
|
width: 185,
|
||||||
render: (text, record: any) =>
|
render: (text, record: any) => record?.subscription?.name || '-',
|
||||||
record.sub_id ? (
|
|
||||||
<Name
|
|
||||||
service={() =>
|
|
||||||
request.get(`${config.apiPrefix}subscriptions/${record.sub_id}`, {
|
|
||||||
onError: noop,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
options={{
|
|
||||||
ready: record?.sub_id,
|
|
||||||
cacheKey: record.sub_id,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
'-'
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: intl.get('操作'),
|
title: intl.get('操作'),
|
||||||
|
@ -392,14 +377,27 @@ const Crontab = () => {
|
||||||
}
|
}
|
||||||
request
|
request
|
||||||
.get(url)
|
.get(url)
|
||||||
.then(({ code, data: _data }) => {
|
.then(async ({ code, data: _data }) => {
|
||||||
if (code === 200) {
|
if (code === 200) {
|
||||||
const { data, total } = _data;
|
const { data, total } = _data;
|
||||||
|
const subscriptions = await request.get(
|
||||||
|
`${config.apiPrefix}subscriptions?ids=${JSON.stringify([
|
||||||
|
...new Set(data.map((x) => x.sub_id).filter(Boolean)),
|
||||||
|
])}`,
|
||||||
|
{
|
||||||
|
onError: noop,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
const subscriptionMap = Object.fromEntries(
|
||||||
|
subscriptions?.data?.map((x) => [x.id, x]),
|
||||||
|
);
|
||||||
|
|
||||||
setValue(
|
setValue(
|
||||||
data.map((x) => {
|
data.map((x) => {
|
||||||
return {
|
return {
|
||||||
...x,
|
...x,
|
||||||
nextRunTime: getCrontabsNextDate(x.schedule, x.extra_schedules),
|
nextRunTime: getCrontabsNextDate(x.schedule, x.extra_schedules),
|
||||||
|
subscription: subscriptionMap?.[x.sub_id],
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user