mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 07:50:25 +08:00 
			
		
		
		
	手动同步集群任务后把所有相关任务标记为已完成
This commit is contained in:
		@@ -201,6 +201,27 @@ func (this *DNSTaskDAO) UpdateDNSTaskDone(tx *dbs.Tx, taskId int64, taskVersion
 | 
			
		||||
	return this.Save(tx, op)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GenerateVersion 生成最新的版本号
 | 
			
		||||
func (this *DNSTaskDAO) GenerateVersion() int64 {
 | 
			
		||||
	return time.Now().UnixNano()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// UpdateClusterDNSTasksDone 设置所有集群任务完成
 | 
			
		||||
func (this *DNSTaskDAO) UpdateClusterDNSTasksDone(tx *dbs.Tx, clusterId int64, maxVersion int64) error {
 | 
			
		||||
	if clusterId <= 0 || maxVersion <= 0 {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return this.Query(tx).
 | 
			
		||||
		Attr("clusterId", clusterId).
 | 
			
		||||
		Attr("isOk", false).
 | 
			
		||||
		Lte("version", maxVersion).
 | 
			
		||||
		Set("isDone", true).
 | 
			
		||||
		Set("isOk", true).
 | 
			
		||||
		Set("error", "").
 | 
			
		||||
		UpdateQuickly()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// DeleteDNSTasksWithClusterId 删除集群相关任务
 | 
			
		||||
func (this *DNSTaskDAO) DeleteDNSTasksWithClusterId(tx *dbs.Tx, clusterId int64) error {
 | 
			
		||||
	if clusterId <= 0 {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,17 +1,28 @@
 | 
			
		||||
package dns
 | 
			
		||||
package dns_test
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/db/models/dns"
 | 
			
		||||
	_ "github.com/go-sql-driver/mysql"
 | 
			
		||||
	_ "github.com/iwind/TeaGo/bootstrap"
 | 
			
		||||
	"github.com/iwind/TeaGo/dbs"
 | 
			
		||||
	"testing"
 | 
			
		||||
	"time"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func TestDNSTaskDAO_CreateDNSTask(t *testing.T) {
 | 
			
		||||
	dbs.NotifyReady()
 | 
			
		||||
	err := SharedDNSTaskDAO.CreateDNSTask(nil, 1, 2, 3, 0, "cdn", "taskType")
 | 
			
		||||
	err := dns.SharedDNSTaskDAO.CreateDNSTask(nil, 1, 2, 3, 0, "cdn", "taskType")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
	t.Log("ok")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestDNSTaskDAO_UpdateClusterDNSTasksDone(t *testing.T) {
 | 
			
		||||
	var dao = dns.NewDNSTaskDAO()
 | 
			
		||||
	var tx *dbs.Tx
 | 
			
		||||
	err := dao.UpdateClusterDNSTasksDone(tx, 46, time.Now().UnixNano())
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -303,7 +303,24 @@ func (this *DNSDomainService) SyncDNSDomainData(ctx context.Context, req *pb.Syn
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return this.syncClusterDNS(req)
 | 
			
		||||
 | 
			
		||||
	var latestVersion = dns.SharedDNSTaskDAO.GenerateVersion()
 | 
			
		||||
 | 
			
		||||
	resp, err := this.syncClusterDNS(req)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return resp, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 标记集群所有任务已完成
 | 
			
		||||
	if req.NodeClusterId > 0 && resp != nil && resp.IsOk {
 | 
			
		||||
		var tx = this.NullTx()
 | 
			
		||||
		err = dns.SharedDNSTaskDAO.UpdateClusterDNSTasksDone(tx, req.NodeClusterId, latestVersion)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return resp, err
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return resp, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// FindAllDNSDomainRoutes 查看支持的线路
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user