DNS任务增加失败重试

This commit is contained in:
GoEdgeLab
2023-08-13 15:26:59 +08:00
parent 75202d946a
commit 99a35cb481
3 changed files with 35 additions and 7 deletions

View File

@@ -66,6 +66,7 @@ func (this *DNSTaskDAO) CreateDNSTask(tx *dbs.Tx, clusterId int64, serverId int6
"isOk": false,
"error": "",
"version": time.Now().UnixNano(),
"countFails": 0,
})
if err != nil {
return err
@@ -108,7 +109,7 @@ func (this *DNSTaskDAO) CreateDomainTask(tx *dbs.Tx, domainId int64, taskType DN
// FindAllDoingTasks 查找所有正在执行的任务
func (this *DNSTaskDAO) FindAllDoingTasks(tx *dbs.Tx) (result []*DNSTask, err error) {
_, err = this.Query(tx).
Attr("isDone", 0).
Where("(isDone=0 OR (isDone=1 AND isOk=0 AND countFails<3))"). // 3 = retry times
Asc("version").
AscPk().
Slice(&result).
@@ -171,6 +172,7 @@ func (this *DNSTaskDAO) UpdateDNSTaskError(tx *dbs.Tx, taskId int64, err string)
op.IsDone = true
op.Error = err
op.IsOk = false
op.CountFails = dbs.SQL("countFails+1")
return this.Save(tx, op)
}
@@ -197,6 +199,7 @@ func (this *DNSTaskDAO) UpdateDNSTaskDone(tx *dbs.Tx, taskId int64, taskVersion
op.Id = taskId
op.IsDone = true
op.IsOk = true
op.CountFails = 0
op.Error = ""
return this.Save(tx, op)
}
@@ -219,6 +222,7 @@ func (this *DNSTaskDAO) UpdateClusterDNSTasksDone(tx *dbs.Tx, clusterId int64, m
Set("isDone", true).
Set("isOk", true).
Set("error", "").
Set("countFails", 0).
UpdateQuickly()
}

View File

@@ -1,5 +1,23 @@
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更新任务
type DNSTask struct {
Id uint64 `field:"id"` // ID
@@ -14,6 +32,7 @@ type DNSTask struct {
IsOk bool `field:"isOk"` // 是否成功
Error string `field:"error"` // 错误信息
Version uint64 `field:"version"` // 版本
CountFails uint32 `field:"countFails"` // 尝试失败次数
}
type DNSTaskOperator struct {
@@ -29,6 +48,7 @@ type DNSTaskOperator struct {
IsOk any // 是否成功
Error any // 错误信息
Version any // 版本
CountFails any // 尝试失败次数
}
func NewDNSTaskOperator() *DNSTaskOperator {

View File

@@ -87506,7 +87506,7 @@
"name": "edgeDNSTasks",
"engine": "InnoDB",
"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": [
{
"name": "id",
@@ -87555,6 +87555,10 @@
{
"name": "version",
"definition": "bigint(20) unsigned DEFAULT '0' COMMENT '版本'"
},
{
"name": "countFails",
"definition": "int(11) unsigned DEFAULT '0' COMMENT '尝试失败次数'"
}
],
"indexes": [