From 4e7a5c637deefe935042f61cf67fa0b671f5a71b Mon Sep 17 00:00:00 2001 From: whyour Date: Tue, 17 May 2022 00:42:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=8B=89=E5=8F=96=E5=85=AC?= =?UTF-8?q?=E5=BC=80=E4=BB=93=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/data/sock.ts | 3 +- back/data/subscription.ts | 1 - back/services/subscription.ts | 18 +++++++++-- src/pages/crontab/index.tsx | 33 +++++--------------- src/pages/crontab/logModal.tsx | 2 +- src/pages/setting/loginLog.tsx | 4 +-- src/pages/subscription/index.tsx | 48 +++++++++++++++++++++++------ src/pages/subscription/logModal.tsx | 4 +-- src/pages/subscription/modal.tsx | 9 ++++-- 9 files changed, 75 insertions(+), 47 deletions(-) diff --git a/back/data/sock.ts b/back/data/sock.ts index 3d280847..ee7d6b11 100644 --- a/back/data/sock.ts +++ b/back/data/sock.ts @@ -15,4 +15,5 @@ export type SockMessageType = | 'installDependence' | 'uninstallDependence' | 'updateSystemVersion' - | 'manuallyRunScript'; + | 'manuallyRunScript' + | 'runSubscriptionEnd'; diff --git a/back/data/subscription.ts b/back/data/subscription.ts index 25b765b8..3d8839a8 100644 --- a/back/data/subscription.ts +++ b/back/data/subscription.ts @@ -40,7 +40,6 @@ export class Subscription { this.blacklist = options.blacklist; this.dependences = options.dependences; this.branch = options.branch; - this.status = options.status; this.pull_type = options.pull_type; this.pull_option = options.pull_option; this.pid = options.pid; diff --git a/back/services/subscription.ts b/back/services/subscription.ts index d14eaa77..f69da5bc 100644 --- a/back/services/subscription.ts +++ b/back/services/subscription.ts @@ -26,12 +26,14 @@ import { Op } from 'sequelize'; import path from 'path'; import ScheduleService, { TaskCallbacks } from './schedule'; import { SimpleIntervalSchedule } from 'toad-scheduler'; +import SockService from './sock'; @Service() export default class SubscriptionService { constructor( @Inject('logger') private logger: winston.Logger, private scheduleService: ScheduleService, + private sockService: SockService, ) {} public async list(searchText?: string): Promise { @@ -94,11 +96,11 @@ export default class SubscriptionService { let command = 'ql '; const { type, url, whitelist, blacklist, dependences, branch } = doc; if (type === 'file') { - command += `raw ${url}`; + command += `raw "${url}"`; } else { - command += `repo ${url} ${whitelist || ''} ${blacklist || ''} ${ + command += `repo "${url}" "${whitelist || ''}" "${blacklist || ''}" "${ dependences || '' - } ${branch || ''}`; + }" "${branch || ''}"`; } return command; } @@ -168,6 +170,11 @@ export default class SubscriptionService { 'YYYY-MM-DD HH:mm:ss', )} 耗时 ${diff} 秒`, ); + this.sockService.sendMessage({ + type: 'runSubscriptionEnd', + message: '订阅执行完成', + references: [doc.id as number], + }); }, onError: async (message: string) => { const sub = await this.getDb({ id: doc.id }); @@ -179,6 +186,7 @@ export default class SubscriptionService { public async create(payload: Subscription): Promise { const tab = new Subscription(payload); + console.log(tab); const doc = await this.insert(tab); this.handleTask(doc); return doc; @@ -231,6 +239,10 @@ export default class SubscriptionService { } public async remove(ids: number[]) { + const docs = await SubscriptionModel.findAll({ where: { id: ids } }); + for (const doc of docs) { + this.handleTask(doc, false); + } await SubscriptionModel.destroy({ where: { id: ids } }); } diff --git a/src/pages/crontab/index.tsx b/src/pages/crontab/index.tsx index 23b2dde0..1b999ce6 100644 --- a/src/pages/crontab/index.tsx +++ b/src/pages/crontab/index.tsx @@ -200,18 +200,9 @@ const Crontab = ({ headerStyle, isPhone, theme }: any) => { }, }, render: (text: string, record: any) => { - const language = navigator.language || navigator.languages[0]; - return ( - - {record.last_running_time - ? diffTime(record.last_running_time) - : '-'} - - ); + return record.last_running_time + ? diffTime(record.last_running_time) + : '-'; }, }, { @@ -225,19 +216,11 @@ const Crontab = ({ headerStyle, isPhone, theme }: any) => { }, render: (text: string, record: any) => { const language = navigator.language || navigator.languages[0]; - return ( - - {record.nextRunTime - .toLocaleString(language, { - hour12: false, - }) - .replace(' 24:', ' 00:')} - - ); + return record.nextRunTime + .toLocaleString(language, { + hour12: false, + }) + .replace(' 24:', ' 00:'); }, }, diff --git a/src/pages/crontab/logModal.tsx b/src/pages/crontab/logModal.tsx index 6ab0a2ff..32ad1d54 100644 --- a/src/pages/crontab/logModal.tsx +++ b/src/pages/crontab/logModal.tsx @@ -95,7 +95,7 @@ const CronLogModal = ({ <> {(executing || loading) && } {!executing && !loading && } - 日志-{cron && cron.name}{' '} + {cron && cron.name} ); }; diff --git a/src/pages/setting/loginLog.tsx b/src/pages/setting/loginLog.tsx index 69087600..5d742ca1 100644 --- a/src/pages/setting/loginLog.tsx +++ b/src/pages/setting/loginLog.tsx @@ -21,7 +21,7 @@ const columns = [ align: 'center' as const, width: 50, render: (text: string, record: any, index: number) => { - return {index + 1} ; + return index + 1; }, }, { @@ -30,7 +30,7 @@ const columns = [ key: 'timestamp', align: 'center' as const, render: (text: string, record: any) => { - return {new Date(record.timestamp).toLocaleString()}; + return new Date(record.timestamp).toLocaleString(); }, }, { diff --git a/src/pages/subscription/index.tsx b/src/pages/subscription/index.tsx index 261524d9..31a4ccd0 100644 --- a/src/pages/subscription/index.tsx +++ b/src/pages/subscription/index.tsx @@ -51,7 +51,7 @@ export enum IntervalSchedule { 'seconds' = '秒', } -const Subscription = ({ headerStyle, isPhone, theme }: any) => { +const Subscription = ({ headerStyle, isPhone, socketMessage }: any) => { const columns: any = [ { title: '名称', @@ -73,6 +73,20 @@ const Subscription = ({ headerStyle, isPhone, theme }: any) => { compare: (a: any, b: any) => a.name.localeCompare(b.name), multiple: 2, }, + render: (text: string, record: any) => { + return ( + + {text} + + ); + }, }, { title: '分支', @@ -80,20 +94,20 @@ const Subscription = ({ headerStyle, isPhone, theme }: any) => { key: 'branch', width: 130, align: 'center' as const, + render: (text: string, record: any) => { + return record.branch || '-'; + }, }, { title: '定时规则', width: 180, align: 'center' as const, render: (text: string, record: any) => { - const { type, value } = record.interval_schedule; - return ( - - {record.schedule_type === 'interval' - ? `每${value}${(IntervalSchedule as any)[type]}` - : record.schedule} - - ); + if (record.schedule_type === 'interval') { + const { type, value } = record.interval_schedule; + return `每${value}${(IntervalSchedule as any)[type]}`; + } + return record.schedule; }, }, { @@ -472,6 +486,22 @@ const Subscription = ({ headerStyle, isPhone, theme }: any) => { : 'subscription'; }; + useEffect(() => { + if (!socketMessage) return; + const { type, message, references } = socketMessage; + if (type === 'runSubscriptionEnd' && references.length > 0) { + const result = [...value]; + for (let i = 0; i < references.length; i++) { + const index = value.findIndex((x) => x.id === references[i]); + result.splice(index, 1, { + ...result[index], + status: SubscriptionStatus.idle, + }); + } + setValue(result); + } + }, [socketMessage]); + useEffect(() => { if (logSubscription) { localStorage.setItem('logSubscription', logSubscription.id); diff --git a/src/pages/subscription/logModal.tsx b/src/pages/subscription/logModal.tsx index 37dd589c..301b640f 100644 --- a/src/pages/subscription/logModal.tsx +++ b/src/pages/subscription/logModal.tsx @@ -68,8 +68,8 @@ const SubscriptionLogModal = ({ {(executing || loading) && } {!executing && !loading && } - 日志-{subscription && subscription.name} - {' '} + {subscription && subscription.name} + ); }; diff --git a/src/pages/subscription/modal.tsx b/src/pages/subscription/modal.tsx index 700044fc..6301a442 100644 --- a/src/pages/subscription/modal.tsx +++ b/src/pages/subscription/modal.tsx @@ -174,6 +174,9 @@ const SubscriptionModal = ({ setType((subscription && subscription.type) || 'public-repo'); setScheduleType((subscription && subscription.schedule_type) || 'crontab'); setPullType((subscription && subscription.pull_type) || 'ssh-key'); + if (!subscription) { + form.resetFields(); + } }, [subscription, visible]); return ( @@ -300,7 +303,7 @@ const SubscriptionModal = ({ {type !== 'file' && ( <>