修复定时任务间隔较小,任务状态不准确

This commit is contained in:
whyour 2023-09-26 22:51:33 +08:00
parent 77a8e00b17
commit eddc03e295
8 changed files with 25 additions and 14 deletions

View File

@ -458,13 +458,12 @@ export default (app: Router) => {
}),
}),
async (req: Request, res: Response, next: NextFunction) => {
const logger: Logger = Container.get('logger');
try {
const cronService = Container.get(CronService);
const data = await cronService.status({
...req.body,
status: parseInt(req.body.status),
pid: parseInt(req.body.pid) || '',
status: req.body.status ? parseInt(req.body.status) : undefined,
pid: req.body.pid ? parseInt(req.body.pid) : undefined,
});
return res.send({ code: 200, data });
} catch (e) {

View File

@ -14,6 +14,8 @@ import cronClient from '../schedule/client';
import taskLimit from '../shared/pLimit';
import { spawn } from 'cross-spawn';
import dayjs from 'dayjs';
import pickBy from 'lodash/pickBy';
import omit from 'lodash/omit';
@Service()
export default class CronService {
@ -89,7 +91,7 @@ export default class CronService {
last_running_time: number;
last_execution_time: number;
}) {
const options: any = {
let options: any = {
status,
pid,
log_path,
@ -99,7 +101,13 @@ export default class CronService {
options.last_running_time = last_running_time;
}
return await CrontabModel.update({ ...options }, { where: { id: ids } });
for (const id of ids) {
const cron = await this.getDb({ id });
if (status === CrontabStatus.idle && log_path !== cron.log_path) {
options = omit(options, ['status', 'log_path', 'pid']);
}
await CrontabModel.update({ ...pickBy(options, (v) => v === 0 || !!v) }, { where: { id } });
}
}
public async remove(ids: number[]) {

View File

@ -460,7 +460,7 @@ handle_task_after() {
[[ "$diff_time" == 0 ]] && diff_time=1
echo -e "\n\n## 执行结束... $end_time 耗时 $diff_time 秒     "
echo -e "\n## 执行结束... $end_time 耗时 $diff_time 秒     "
[[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time"
}

View File

@ -25,8 +25,8 @@ body {
}
.ant-modal-body {
max-height: calc(90vh - 110px);
max-height: calc(90vh - var(--vh-offset, 110px));
max-height: calc(80vh - 110px);
max-height: calc(80vh - var(--vh-offset, 110px));
overflow-y: auto;
}
@ -181,6 +181,7 @@ body {
.react-codemirror2,
.CodeMirror {
height: 100%;
overflow: auto;
}
}
}

View File

@ -10,6 +10,7 @@ import {
import { PageLoading } from '@ant-design/pro-layout';
import { logEnded } from '@/utils';
import { CrontabStatus } from './type';
import Ansi from 'ansi-to-react';
const { Countdown } = Statistic;
@ -148,7 +149,7 @@ const CronLogModal = ({
: {}
}
>
{value}
<Ansi>{value}</Ansi>
</pre>
)}
<div id="log-flag"></div>

View File

@ -16,6 +16,7 @@ import SettingModal from './setting';
import { useTheme } from '@/utils/hooks';
import { getEditorMode, logEnded } from '@/utils';
import WebSocketManager from '@/utils/websocket';
import Ansi from 'ansi-to-react';
const { Option } = Select;
@ -116,7 +117,7 @@ const EditModal = ({
}, 300);
}
setLog(p=>`${p}${_message}`);
setLog((p) => `${p}${_message}`);
}, []);
useEffect(() => {
@ -246,7 +247,7 @@ const EditModal = ({
padding: '0 15px',
}}
>
{log}
<Ansi>{log}</Ansi>
</pre>
</SplitPane>
<SaveModal

View File

@ -77,7 +77,7 @@ const CheckUpdate = ({ systemInfo }: any) => {
</div>
</>
),
content: <pre>{lastLog}</pre>,
content: <pre><Ansi>{lastLog}</Ansi></pre>,
okText: intl.get('下载更新'),
cancelText: intl.get('以后再说'),
onOk() {
@ -102,7 +102,7 @@ const CheckUpdate = ({ systemInfo }: any) => {
okButtonProps: { disabled: true },
title: intl.get('下载更新中...'),
centered: true,
content: <pre>{value}</pre>,
content: <pre><Ansi>{value}</Ansi></pre>,
});
};

View File

@ -9,6 +9,7 @@ import {
} from '@ant-design/icons';
import { PageLoading } from '@ant-design/pro-layout';
import { logEnded } from '@/utils';
import Ansi from 'ansi-to-react';
const SubscriptionLogModal = ({
subscription,
@ -122,7 +123,7 @@ const SubscriptionLogModal = ({
: {}
}
>
{value}
<Ansi>{value}</Ansi>
</pre>
)}
</div>