mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-17 09:34:31 +08:00
重构任务执行逻辑
This commit is contained in:
@@ -477,6 +477,13 @@ const Subscription = ({ headerStyle, isPhone, theme }: any) => {
|
||||
: 'subscription';
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (logSubscription) {
|
||||
localStorage.setItem('logSubscription', logSubscription.id);
|
||||
setIsLogModalVisible(true);
|
||||
}
|
||||
}, [logSubscription]);
|
||||
|
||||
useEffect(() => {
|
||||
getSubscriptions();
|
||||
}, [searchText]);
|
||||
@@ -541,7 +548,7 @@ const Subscription = ({ headerStyle, isPhone, theme }: any) => {
|
||||
handleCancel={() => {
|
||||
setIsLogModalVisible(false);
|
||||
}}
|
||||
cron={logSubscription}
|
||||
subscription={logSubscription}
|
||||
/>
|
||||
</PageContainer>
|
||||
);
|
||||
|
||||
@@ -8,22 +8,14 @@ import {
|
||||
} from '@ant-design/icons';
|
||||
import { PageLoading } from '@ant-design/pro-layout';
|
||||
|
||||
enum CrontabStatus {
|
||||
'running',
|
||||
'idle',
|
||||
'disabled',
|
||||
'queued',
|
||||
}
|
||||
const { Countdown } = Statistic;
|
||||
|
||||
const SubscriptionLogModal = ({
|
||||
cron,
|
||||
subscription,
|
||||
handleCancel,
|
||||
visible,
|
||||
data,
|
||||
logUrl,
|
||||
}: {
|
||||
cron?: any;
|
||||
subscription?: any;
|
||||
visible: boolean;
|
||||
handleCancel: () => void;
|
||||
data?: string;
|
||||
@@ -33,49 +25,29 @@ const SubscriptionLogModal = ({
|
||||
const [loading, setLoading] = useState<any>(true);
|
||||
const [executing, setExecuting] = useState<any>(true);
|
||||
const [isPhone, setIsPhone] = useState(false);
|
||||
const [theme, setTheme] = useState<string>('');
|
||||
|
||||
const getCronLog = (isFirst?: boolean) => {
|
||||
if (isFirst) {
|
||||
setLoading(true);
|
||||
}
|
||||
request
|
||||
.get(logUrl ? logUrl : `${config.apiPrefix}crons/${cron.id}/log`)
|
||||
.get(
|
||||
logUrl
|
||||
? logUrl
|
||||
: `${config.apiPrefix}subscriptions/${subscription.id}/log`,
|
||||
)
|
||||
.then((data: any) => {
|
||||
if (localStorage.getItem('logCron') === String(cron.id)) {
|
||||
if (
|
||||
localStorage.getItem('logSubscription') === String(subscription.id)
|
||||
) {
|
||||
const log = data.data as string;
|
||||
setValue(log || '暂无日志');
|
||||
setExecuting(
|
||||
log && !log.includes('执行结束') && !log.includes('重启面板'),
|
||||
);
|
||||
if (log && !log.includes('执行结束') && !log.includes('重启面板')) {
|
||||
setExecuting(log && !log.includes('执行结束'));
|
||||
if (log && !log.includes('执行结束')) {
|
||||
setTimeout(() => {
|
||||
getCronLog();
|
||||
}, 2000);
|
||||
}
|
||||
if (
|
||||
log &&
|
||||
log.includes('重启面板') &&
|
||||
cron.status === CrontabStatus.running
|
||||
) {
|
||||
message.warning({
|
||||
content: (
|
||||
<span>
|
||||
系统将在
|
||||
<Countdown
|
||||
className="inline-countdown"
|
||||
format="ss"
|
||||
value={Date.now() + 1000 * 30}
|
||||
/>
|
||||
秒后自动刷新
|
||||
</span>
|
||||
),
|
||||
duration: 10,
|
||||
});
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 30000);
|
||||
}
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
@@ -86,7 +58,7 @@ const SubscriptionLogModal = ({
|
||||
};
|
||||
|
||||
const cancel = () => {
|
||||
localStorage.removeItem('logCron');
|
||||
localStorage.removeItem('logSubscription');
|
||||
handleCancel();
|
||||
};
|
||||
|
||||
@@ -95,16 +67,18 @@ const SubscriptionLogModal = ({
|
||||
<>
|
||||
{(executing || loading) && <Loading3QuartersOutlined spin />}
|
||||
{!executing && !loading && <CheckCircleOutlined />}
|
||||
<span style={{ marginLeft: 5 }}>日志-{cron && cron.name}</span>{' '}
|
||||
<span style={{ marginLeft: 5 }}>
|
||||
日志-{subscription && subscription.name}
|
||||
</span>{' '}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (cron && cron.id && visible) {
|
||||
if (subscription && subscription.id && visible) {
|
||||
getCronLog(true);
|
||||
}
|
||||
}, [cron, visible]);
|
||||
}, [subscription, visible]);
|
||||
|
||||
useEffect(() => {
|
||||
if (data) {
|
||||
|
||||
Reference in New Issue
Block a user