mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-03 15:00:27 +08:00
DNS任务增加失败重试
This commit is contained in:
@@ -61,11 +61,12 @@ func (this *DNSTaskDAO) CreateDNSTask(tx *dbs.Tx, clusterId int64, serverId int6
|
|||||||
"error": "",
|
"error": "",
|
||||||
"version": time.Now().UnixNano(),
|
"version": time.Now().UnixNano(),
|
||||||
}, maps.Map{
|
}, maps.Map{
|
||||||
"updatedAt": time.Now().Unix(),
|
"updatedAt": time.Now().Unix(),
|
||||||
"isDone": false,
|
"isDone": false,
|
||||||
"isOk": false,
|
"isOk": false,
|
||||||
"error": "",
|
"error": "",
|
||||||
"version": time.Now().UnixNano(),
|
"version": time.Now().UnixNano(),
|
||||||
|
"countFails": 0,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -108,7 +109,7 @@ func (this *DNSTaskDAO) CreateDomainTask(tx *dbs.Tx, domainId int64, taskType DN
|
|||||||
// FindAllDoingTasks 查找所有正在执行的任务
|
// FindAllDoingTasks 查找所有正在执行的任务
|
||||||
func (this *DNSTaskDAO) FindAllDoingTasks(tx *dbs.Tx) (result []*DNSTask, err error) {
|
func (this *DNSTaskDAO) FindAllDoingTasks(tx *dbs.Tx) (result []*DNSTask, err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
Attr("isDone", 0).
|
Where("(isDone=0 OR (isDone=1 AND isOk=0 AND countFails<3))"). // 3 = retry times
|
||||||
Asc("version").
|
Asc("version").
|
||||||
AscPk().
|
AscPk().
|
||||||
Slice(&result).
|
Slice(&result).
|
||||||
@@ -171,6 +172,7 @@ func (this *DNSTaskDAO) UpdateDNSTaskError(tx *dbs.Tx, taskId int64, err string)
|
|||||||
op.IsDone = true
|
op.IsDone = true
|
||||||
op.Error = err
|
op.Error = err
|
||||||
op.IsOk = false
|
op.IsOk = false
|
||||||
|
op.CountFails = dbs.SQL("countFails+1")
|
||||||
return this.Save(tx, op)
|
return this.Save(tx, op)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,6 +199,7 @@ func (this *DNSTaskDAO) UpdateDNSTaskDone(tx *dbs.Tx, taskId int64, taskVersion
|
|||||||
op.Id = taskId
|
op.Id = taskId
|
||||||
op.IsDone = true
|
op.IsDone = true
|
||||||
op.IsOk = true
|
op.IsOk = true
|
||||||
|
op.CountFails = 0
|
||||||
op.Error = ""
|
op.Error = ""
|
||||||
return this.Save(tx, op)
|
return this.Save(tx, op)
|
||||||
}
|
}
|
||||||
@@ -219,6 +222,7 @@ func (this *DNSTaskDAO) UpdateClusterDNSTasksDone(tx *dbs.Tx, clusterId int64, m
|
|||||||
Set("isDone", true).
|
Set("isDone", true).
|
||||||
Set("isOk", true).
|
Set("isOk", true).
|
||||||
Set("error", "").
|
Set("error", "").
|
||||||
|
Set("countFails", 0).
|
||||||
UpdateQuickly()
|
UpdateQuickly()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,23 @@
|
|||||||
package dns
|
package dns
|
||||||
|
|
||||||
|
import "github.com/iwind/TeaGo/dbs"
|
||||||
|
|
||||||
|
const (
|
||||||
|
DNSTaskField_Id dbs.FieldName = "id" // ID
|
||||||
|
DNSTaskField_ClusterId dbs.FieldName = "clusterId" // 集群ID
|
||||||
|
DNSTaskField_ServerId dbs.FieldName = "serverId" // 服务ID
|
||||||
|
DNSTaskField_NodeId dbs.FieldName = "nodeId" // 节点ID
|
||||||
|
DNSTaskField_DomainId dbs.FieldName = "domainId" // 域名ID
|
||||||
|
DNSTaskField_RecordName dbs.FieldName = "recordName" // 记录名
|
||||||
|
DNSTaskField_Type dbs.FieldName = "type" // 任务类型
|
||||||
|
DNSTaskField_UpdatedAt dbs.FieldName = "updatedAt" // 更新时间
|
||||||
|
DNSTaskField_IsDone dbs.FieldName = "isDone" // 是否已完成
|
||||||
|
DNSTaskField_IsOk dbs.FieldName = "isOk" // 是否成功
|
||||||
|
DNSTaskField_Error dbs.FieldName = "error" // 错误信息
|
||||||
|
DNSTaskField_Version dbs.FieldName = "version" // 版本
|
||||||
|
DNSTaskField_CountFails dbs.FieldName = "countFails" // 尝试失败次数
|
||||||
|
)
|
||||||
|
|
||||||
// DNSTask DNS更新任务
|
// DNSTask DNS更新任务
|
||||||
type DNSTask struct {
|
type DNSTask struct {
|
||||||
Id uint64 `field:"id"` // ID
|
Id uint64 `field:"id"` // ID
|
||||||
@@ -14,6 +32,7 @@ type DNSTask struct {
|
|||||||
IsOk bool `field:"isOk"` // 是否成功
|
IsOk bool `field:"isOk"` // 是否成功
|
||||||
Error string `field:"error"` // 错误信息
|
Error string `field:"error"` // 错误信息
|
||||||
Version uint64 `field:"version"` // 版本
|
Version uint64 `field:"version"` // 版本
|
||||||
|
CountFails uint32 `field:"countFails"` // 尝试失败次数
|
||||||
}
|
}
|
||||||
|
|
||||||
type DNSTaskOperator struct {
|
type DNSTaskOperator struct {
|
||||||
@@ -29,6 +48,7 @@ type DNSTaskOperator struct {
|
|||||||
IsOk any // 是否成功
|
IsOk any // 是否成功
|
||||||
Error any // 错误信息
|
Error any // 错误信息
|
||||||
Version any // 版本
|
Version any // 版本
|
||||||
|
CountFails any // 尝试失败次数
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDNSTaskOperator() *DNSTaskOperator {
|
func NewDNSTaskOperator() *DNSTaskOperator {
|
||||||
|
|||||||
@@ -87506,7 +87506,7 @@
|
|||||||
"name": "edgeDNSTasks",
|
"name": "edgeDNSTasks",
|
||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"charset": "utf8mb4_general_ci",
|
"charset": "utf8mb4_general_ci",
|
||||||
"definition": "CREATE TABLE `edgeDNSTasks` (\n `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `clusterId` int(11) unsigned DEFAULT '0' COMMENT '集群ID',\n `serverId` int(11) unsigned DEFAULT '0' COMMENT '服务ID',\n `nodeId` int(11) unsigned DEFAULT '0' COMMENT '节点ID',\n `domainId` int(11) unsigned DEFAULT '0' COMMENT '域名ID',\n `recordName` varchar(255) DEFAULT NULL COMMENT '记录名',\n `type` varchar(255) DEFAULT NULL COMMENT '任务类型',\n `updatedAt` bigint(11) unsigned DEFAULT '0' COMMENT '更新时间',\n `isDone` tinyint(1) unsigned DEFAULT '0' COMMENT '是否已完成',\n `isOk` tinyint(1) unsigned DEFAULT '0' COMMENT '是否成功',\n `error` varchar(1024) DEFAULT NULL COMMENT '错误信息',\n `version` bigint(20) unsigned DEFAULT '0' COMMENT '版本',\n PRIMARY KEY (`id`),\n UNIQUE KEY `uniqueId` (`clusterId`,`serverId`,`nodeId`,`domainId`,`recordName`,`type`) USING BTREE,\n KEY `isDone` (`isDone`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='DNS更新任务'",
|
"definition": "CREATE TABLE `edgeDNSTasks` (\n `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `clusterId` int(11) unsigned DEFAULT '0' COMMENT '集群ID',\n `serverId` int(11) unsigned DEFAULT '0' COMMENT '服务ID',\n `nodeId` int(11) unsigned DEFAULT '0' COMMENT '节点ID',\n `domainId` int(11) unsigned DEFAULT '0' COMMENT '域名ID',\n `recordName` varchar(255) DEFAULT NULL COMMENT '记录名',\n `type` varchar(255) DEFAULT NULL COMMENT '任务类型',\n `updatedAt` bigint(11) unsigned DEFAULT '0' COMMENT '更新时间',\n `isDone` tinyint(1) unsigned DEFAULT '0' COMMENT '是否已完成',\n `isOk` tinyint(1) unsigned DEFAULT '0' COMMENT '是否成功',\n `error` varchar(1024) DEFAULT NULL COMMENT '错误信息',\n `version` bigint(20) unsigned DEFAULT '0' COMMENT '版本',\n `countFails` int(11) unsigned DEFAULT '0' COMMENT '尝试失败次数',\n PRIMARY KEY (`id`),\n UNIQUE KEY `uniqueId` (`clusterId`,`serverId`,`nodeId`,`domainId`,`recordName`,`type`) USING BTREE,\n KEY `isDone` (`isDone`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='DNS更新任务'",
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"name": "id",
|
"name": "id",
|
||||||
@@ -87555,6 +87555,10 @@
|
|||||||
{
|
{
|
||||||
"name": "version",
|
"name": "version",
|
||||||
"definition": "bigint(20) unsigned DEFAULT '0' COMMENT '版本'"
|
"definition": "bigint(20) unsigned DEFAULT '0' COMMENT '版本'"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "countFails",
|
||||||
|
"definition": "int(11) unsigned DEFAULT '0' COMMENT '尝试失败次数'"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"indexes": [
|
"indexes": [
|
||||||
|
|||||||
Reference in New Issue
Block a user