重构任务执行逻辑

This commit is contained in:
whyour
2022-05-15 20:40:29 +08:00
parent bb47d67d0b
commit 9dcc547ac7
7 changed files with 204 additions and 190 deletions
+8 -1
View File
@@ -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>
);
+18 -44
View File
@@ -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) {