mirror of
https://github.com/certd/certd.git
synced 2026-04-14 12:30:54 +08:00
chore: domain import task
This commit is contained in:
@@ -319,4 +319,109 @@ h6 {
|
||||
|
||||
.ant-input-number{
|
||||
min-width: 100px;
|
||||
}
|
||||
|
||||
|
||||
.cd-table {
|
||||
/* 我的客户样式 */
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
overflow: auto;
|
||||
|
||||
.fs-loading{
|
||||
position: absolute;
|
||||
left :0;
|
||||
top :0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.05);
|
||||
z-index: 10000
|
||||
}
|
||||
|
||||
table {
|
||||
width: 1000px;
|
||||
min-width: 100%;
|
||||
table-layout: fixed;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
thead {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.position-sticky-right {
|
||||
position: sticky;
|
||||
right: 0;
|
||||
z-index: 100;
|
||||
border-left: 0px;
|
||||
|
||||
&::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
width: 1px;
|
||||
/* 边框宽度 */
|
||||
background: #eee;
|
||||
/* 边框颜色 */
|
||||
}
|
||||
}
|
||||
|
||||
th,
|
||||
td {
|
||||
|
||||
text-align: left;
|
||||
border-bottom: 1px solid #eee;
|
||||
border-left: 1px solid #eee;
|
||||
}
|
||||
|
||||
th {
|
||||
padding: 15px 5px;
|
||||
background: #f5f7ff;
|
||||
font-weight: 600;
|
||||
color: #6e8efb;
|
||||
font-size: 14px;
|
||||
|
||||
&:last-child {
|
||||
border-right: 1px solid #eee;
|
||||
}
|
||||
}
|
||||
|
||||
td {
|
||||
padding: 10px;
|
||||
font-size: 14px;
|
||||
|
||||
&:last-child {
|
||||
border-right: 1px solid #eee;
|
||||
}
|
||||
}
|
||||
|
||||
td.position-sticky-right {
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
|
||||
tr.hover-color:hover td {
|
||||
background: #f9f9ff;
|
||||
}
|
||||
|
||||
.status {
|
||||
padding: 5px 10px;
|
||||
border-radius: 20px;
|
||||
font-size: 0.8rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.status-active {
|
||||
background: #e7f6e9;
|
||||
color: #2e7d32;
|
||||
}
|
||||
|
||||
.status-pending {
|
||||
background: #ffecb3;
|
||||
color: #f57c00;
|
||||
}
|
||||
}
|
||||
@@ -71,18 +71,18 @@ export async function ImportTaskStatus() {
|
||||
method: "post",
|
||||
});
|
||||
}
|
||||
export async function ImportTaskDelete(key: any) {
|
||||
export async function ImportTaskDelete(key: string) {
|
||||
return await request({
|
||||
url: apiPrefix + "/import/delete",
|
||||
method: "post",
|
||||
params: { key },
|
||||
data: { key },
|
||||
});
|
||||
}
|
||||
export async function ImportTaskStart(key: any) {
|
||||
export async function ImportTaskStart(key: string) {
|
||||
return await request({
|
||||
url: apiPrefix + "/import/start",
|
||||
method: "post",
|
||||
params: { key },
|
||||
data: { key },
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import { Modal, notification } from "ant-design-vue";
|
||||
import { Ref, ref } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
import * as api from "./api";
|
||||
import DomainImportTaskStatus from "./domain-import-task-status.vue";
|
||||
import DomainImportTaskStatus from "./import.vue";
|
||||
import { Dicts } from "/@/components/plugins/lib/dicts";
|
||||
import { useSettingStore } from "/@/store/settings";
|
||||
import { useUserStore } from "/@/store/user";
|
||||
|
||||
@@ -1,29 +1,46 @@
|
||||
<template>
|
||||
<div class="domain-import-task-status">
|
||||
<div class="domain-import-task-status min-h-[400px]">
|
||||
<div class="action">
|
||||
<fs-button type="primary" size="small" icon="ion:add-outline" @click="addTask">添加导入任务</fs-button>
|
||||
<fs-button type="primary" icon="ion:add-outline" @click="addTask">添加导入任务</fs-button>
|
||||
<fs-button type="primary" icon="ion:refresh-outline" class="ml-2" @click="loadImportTaskStatus">刷新</fs-button>
|
||||
</div>
|
||||
<div class="table-container overflow-auto mt-2">
|
||||
<table class="cd-table border-gray-300 w-full">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="w-20%">来源</th>
|
||||
<th>进度</th>
|
||||
<th class="w-20%">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="item in list" :key="item.key">
|
||||
<td class="ellipsis">{{ item.title }}</td>
|
||||
<td>
|
||||
<div v-if="item.task">
|
||||
<div>
|
||||
<a-tag color="blue">总数:{{ item.task?.total }}</a-tag>
|
||||
<a-tag color="success" class="ml-2">成功:{{ item.task?.successCount }}</a-tag>
|
||||
<a-tag type="info" class="ml-2">跳过:{{ item.task?.skipCount }}</a-tag>
|
||||
<a-tooltip v-if="item.task?.errors.length > 0">
|
||||
<template #title>
|
||||
<div v-for="error in item.task?.errors" :key="error">{{ error }}</div>
|
||||
</template>
|
||||
<a-tag color="red" class="ml-2">失败:{{ item.task?.errors.length }}</a-tag>
|
||||
</a-tooltip>
|
||||
</div>
|
||||
<a-progress :percent="item.task?.progress" size="small" status="active" />
|
||||
</div>
|
||||
<div v-else>未执行</div>
|
||||
</td>
|
||||
<td>
|
||||
<fs-button type="primary" icon="ion:play-outline" @click="startTask(item)">执行</fs-button>
|
||||
<fs-button type="primary" class="ml-2" danger icon="ion:trash-outline" @click="deleteTask(item)">删除</fs-button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>标题</th>
|
||||
<th>进度</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="item in list" :key="item.taskId">
|
||||
<td>{{ item.title }}</td>
|
||||
<td>
|
||||
<a-progress :percent="item.percent" size="small" status="active" />
|
||||
</td>
|
||||
<td>
|
||||
<fs-button type="primary" size="small" icon="ion:play-outline" @click="startTask(item)">执行</fs-button>
|
||||
<fs-button type="danger" size="small" icon="ion:stop-outline" @click="deleteTask(item)">删除</fs-button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -44,7 +61,7 @@ async function loadImportTaskStatus() {
|
||||
}
|
||||
|
||||
async function startTask(item: any) {
|
||||
await api.ImportTaskStart(item);
|
||||
await api.ImportTaskStart(item.key);
|
||||
await loadImportTaskStatus();
|
||||
}
|
||||
|
||||
@@ -54,7 +71,7 @@ async function deleteTask(item: any) {
|
||||
okText: "确认",
|
||||
okType: "danger",
|
||||
onOk: async () => {
|
||||
await api.ImportTaskDelete(item.taskId);
|
||||
await api.ImportTaskDelete(item.key);
|
||||
await loadImportTaskStatus();
|
||||
},
|
||||
});
|
||||
@@ -74,3 +91,11 @@ onMounted(async () => {
|
||||
await loadImportTaskStatus();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="less">
|
||||
.domain-import-task-status {
|
||||
.table-container {
|
||||
height: 60vh;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -2,6 +2,7 @@ import { message } from "ant-design-vue";
|
||||
import * as api from "./api";
|
||||
import { useFormDialog } from "/@/use/use-dialog";
|
||||
import { compute } from "@fast-crud/fast-crud";
|
||||
import { Dicts } from "/@/components/plugins/lib/dicts";
|
||||
|
||||
export function useDomainImport() {
|
||||
const { openFormDialog } = useFormDialog();
|
||||
@@ -13,11 +14,12 @@ export function useDomainImport() {
|
||||
form: {
|
||||
component: {
|
||||
name: "dns-provider-selector",
|
||||
},
|
||||
on: {
|
||||
//@ts-ignore
|
||||
onSelectedChange: ({ form, $event }) => {
|
||||
form.dnsProviderAccessType = $event.accessType;
|
||||
on: {
|
||||
//@ts-ignore
|
||||
selectedChange: ({ form, $event }) => {
|
||||
form.dnsProviderAccessType = $event.accessType;
|
||||
form.dnsProviderTitle = $event.label;
|
||||
},
|
||||
},
|
||||
},
|
||||
//@ts-ignore
|
||||
@@ -43,6 +45,12 @@ export function useDomainImport() {
|
||||
type: compute(({ form }) => {
|
||||
return form.dnsProviderAccessType || form.dnsProviderType;
|
||||
}),
|
||||
on: {
|
||||
//@ts-ignore
|
||||
selectedChange({ form, $event }) {
|
||||
form.accessTitle = $event.name;
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -56,6 +64,7 @@ export function useDomainImport() {
|
||||
await api.ImportTaskAdd({
|
||||
dnsProviderType: form.dnsProviderType,
|
||||
dnsProviderAccessId: form.dnsProviderAccessId,
|
||||
title: form.dnsProviderTitle + "_" + form.accessTitle,
|
||||
});
|
||||
if (req.afterSubmit) {
|
||||
req.afterSubmit();
|
||||
|
||||
@@ -220,7 +220,7 @@ export class AutoCRegisterCron {
|
||||
name: 'domain-expire-check',
|
||||
cron: `0 ${randomMinute} ${randomHour} ? * ${randomWeek}`, // 每周随机一天检查一次
|
||||
job: async () => {
|
||||
await this.domainService.doSyncDomainsExpirationDate({})
|
||||
await this.domainService.startSyncExpirationTask({})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -9,8 +9,11 @@ export class BackTaskExecutor {
|
||||
this.tasks[type] = {}
|
||||
}
|
||||
const oldTask = this.tasks[type][task.key]
|
||||
if (oldTask && oldTask.status === "running") {
|
||||
throw new Error(`任务 ${task.title} 正在运行中`)
|
||||
if (oldTask ){
|
||||
if (oldTask.status === "running") {
|
||||
throw new Error(`任务 ${task.title} 正在运行中`)
|
||||
}
|
||||
this.clear(type, task.key);
|
||||
}
|
||||
this.tasks[type][task.key] = task
|
||||
this.run(task);
|
||||
@@ -55,9 +58,9 @@ export class BackTaskExecutor {
|
||||
} finally {
|
||||
task.endTime = Date.now();
|
||||
task.status = "done";
|
||||
task.timeoutId = setTimeout(() => {
|
||||
task.setTimeoutId(setTimeout(() => {
|
||||
this.clear(type, task.key);
|
||||
}, 24 * 60 * 60 * 1000);
|
||||
}, 24 * 60 * 60 * 1000));
|
||||
delete task.run;
|
||||
}
|
||||
}
|
||||
@@ -76,11 +79,11 @@ export class BackTask {
|
||||
endTime: number;
|
||||
status: string = "pending";
|
||||
errors?: string[] = [];
|
||||
timeoutId?: NodeJS.Timeout;
|
||||
private _timeoutId?: NodeJS.Timeout;
|
||||
|
||||
|
||||
|
||||
run: (task: BackTask) => Promise<void>;
|
||||
private _run: (task: BackTask) => Promise<void>;
|
||||
|
||||
constructor(opts: {
|
||||
type: string,
|
||||
@@ -90,21 +93,64 @@ export class BackTask {
|
||||
this.type = type
|
||||
this.key = key;
|
||||
this.title = title;
|
||||
Object.defineProperty(this, 'run', {
|
||||
value: run,
|
||||
writable: true,
|
||||
enumerable: false, // 设置为false使其不可遍历
|
||||
this._run = run;
|
||||
|
||||
Object.defineProperty(this, '_run', {
|
||||
enumerable: false,
|
||||
value: this._run
|
||||
})
|
||||
Object.defineProperty(this, '_timeoutId', {
|
||||
enumerable: false,
|
||||
value: null
|
||||
})
|
||||
|
||||
Object.defineProperty(this, 'progress', {
|
||||
get: ()=> {
|
||||
return this.getProgress()
|
||||
},
|
||||
enumerable: true, // 关键:设置为可枚举
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(this, 'successCount', {
|
||||
get: ()=> {
|
||||
return this.getSuccessCount()
|
||||
},
|
||||
enumerable: true, // 关键:设置为可枚举
|
||||
configurable: true
|
||||
})
|
||||
Object.defineProperty(this, 'errorCount', {
|
||||
get: ()=> {
|
||||
return this.getErrorCount()
|
||||
},
|
||||
enumerable: true, // 关键:设置为可枚举
|
||||
configurable: true
|
||||
})
|
||||
Object.defineProperty(this, 'skipCount', {
|
||||
get: ()=> {
|
||||
return this.getSkipCount()
|
||||
},
|
||||
enumerable: true, // 关键:设置为可枚举
|
||||
configurable: true
|
||||
})
|
||||
}
|
||||
|
||||
async run(task: BackTask) {
|
||||
return await this._run(task);
|
||||
}
|
||||
|
||||
clearTimeout() {
|
||||
if (this.timeoutId) {
|
||||
clearTimeout(this.timeoutId);
|
||||
this.timeoutId = null;
|
||||
if (this._timeoutId) {
|
||||
clearTimeout(this._timeoutId);
|
||||
this._timeoutId = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
setTimeoutId(timeoutId: NodeJS.Timeout) {
|
||||
this.clearTimeout();
|
||||
this._timeoutId = timeoutId;
|
||||
}
|
||||
|
||||
setTotal(total: number) {
|
||||
this.total = total;
|
||||
}
|
||||
@@ -117,22 +163,23 @@ export class BackTask {
|
||||
this.errors.push(error)
|
||||
}
|
||||
|
||||
getSuccessCount() {
|
||||
return this.current - this.errors.length
|
||||
}
|
||||
|
||||
getErrorCount() {
|
||||
return this.errors.length
|
||||
}
|
||||
|
||||
getProgress() {
|
||||
return (this.current / this.total * 1.0).toFixed(2)
|
||||
}
|
||||
|
||||
getSkipCount() {
|
||||
return this.skip
|
||||
}
|
||||
|
||||
getSuccessCount() {
|
||||
return this.current - this.errors.length
|
||||
}
|
||||
|
||||
getProgress() {
|
||||
return (this.current * 1.0 / this.total * 100.0);
|
||||
}
|
||||
|
||||
|
||||
incrementSkip() {
|
||||
this.skip++
|
||||
}
|
||||
|
||||
@@ -7,15 +7,15 @@ import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import dayjs from 'dayjs';
|
||||
import { In, Not, Repository } from 'typeorm';
|
||||
import { BackTask, taskExecutor } from '../../basic/service/task-executor.js';
|
||||
import { CnameRecordEntity } from "../../cname/entity/cname-record.js";
|
||||
import { CnameRecordService } from '../../cname/service/cname-record-service.js';
|
||||
import { UserDomainImportSetting } from '../../mine/service/models.js';
|
||||
import { UserSettingsService } from '../../mine/service/user-settings-service.js';
|
||||
import { SubDomainsGetter } from '../../pipeline/service/getter/sub-domain-getter.js';
|
||||
import { TaskServiceBuilder } from '../../pipeline/service/getter/task-service-getter.js';
|
||||
import { SubDomainService } from "../../pipeline/service/sub-domain-service.js";
|
||||
import { DomainEntity } from '../entity/domain.js';
|
||||
import { BackTask, taskExecutor } from '../../basic/service/task-executor.js';
|
||||
import { UserSettingsService } from '../../mine/service/user-settings-service.js';
|
||||
import { UserDomainImportSetting } from '../../mine/service/models.js';
|
||||
|
||||
export interface SyncFromProviderReq {
|
||||
userId: number;
|
||||
@@ -306,7 +306,7 @@ export class DomainService extends BaseService<DomainEntity> {
|
||||
}
|
||||
await doPageTurn({ pager, getPage, itemHandle, batchHandle })
|
||||
const key = `user_${userId || 0}`
|
||||
logger.info(`从域名提供商${dnsProviderType}导入域名完成(${key}),共导入${task.current}个域名,跳过${task.getSkipCount()}个域名`)
|
||||
logger.info(`从域名提供商${dnsProviderType}导入域名完成(${key}),共导入${task.total}个域名,跳过${task.getSkipCount()}个域名,成功${task.getSuccessCount()}个域名,失败${task.getErrorCount()}个域名`)
|
||||
}
|
||||
|
||||
async getDomainImportTaskStatus(req:{userId?:number}) {
|
||||
@@ -324,7 +324,7 @@ export class DomainService extends BaseService<DomainEntity> {
|
||||
|
||||
taskList.push({
|
||||
...item,
|
||||
task,
|
||||
task:task,
|
||||
})
|
||||
}
|
||||
return taskList
|
||||
@@ -377,7 +377,7 @@ export class DomainService extends BaseService<DomainEntity> {
|
||||
|
||||
|
||||
async getSyncExpirationTaskStatus(req:{userId?:number}) {
|
||||
const userId = req.userId || 0
|
||||
const userId = req.userId ?? 'all'
|
||||
const key = `user_${userId}`
|
||||
const task = taskExecutor.get(DOMAIN_EXPIRE_TASK_TYPE,key)
|
||||
return task
|
||||
@@ -385,7 +385,7 @@ export class DomainService extends BaseService<DomainEntity> {
|
||||
|
||||
async startSyncExpirationTask(req: { userId?: number }) {
|
||||
const userId = req.userId
|
||||
const key = `user_${userId || 0}`
|
||||
const key = `user_${userId ?? 'all'}`
|
||||
taskExecutor.start(new BackTask({
|
||||
type: DOMAIN_EXPIRE_TASK_TYPE,
|
||||
key,
|
||||
@@ -501,7 +501,7 @@ export class DomainService extends BaseService<DomainEntity> {
|
||||
|
||||
await doPageTurn({ pager, getPage: getDomainPage, itemHandle: itemHandle })
|
||||
const key = `user_${req.userId || 'all'}`
|
||||
logger.info(`同步用户(${key})注册域名过期时间完成(${req.task.getSuccessCount()}个成功,${req.task.errors.length}个失败)` )
|
||||
logger.info(`同步用户(${key})注册域名过期时间完成(${req.task.getSuccessCount()}个成功,${req.task.getErrorCount()}个失败)` )
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -499,7 +499,8 @@ export class CnameRecordService extends BaseService<CnameRecordEntity> {
|
||||
throw new ValidateException("CNAME服务提供商不能为空");
|
||||
}
|
||||
|
||||
taskExecutor.start("cnameImport",new BackTask({
|
||||
taskExecutor.start(new BackTask({
|
||||
type:"cnameImport",
|
||||
key: "user_"+userId,
|
||||
title: "导入CNAME记录",
|
||||
run: async (task) => {
|
||||
|
||||
Reference in New Issue
Block a user